donavon
donavon

Reputation: 13

I'm having trouble grabbing an html input value using BeautifulSoup

I need to grab the value of the attribute value inside this HTML element

<option value="1129070-040" data-size="US9.5" data-stock="In_Stock" data-morecomingsoon="true">

I can't seem to find a way in bs4 documentation

Upvotes: 1

Views: 38

Answers (1)

Nazim Kerimbekov
Nazim Kerimbekov

Reputation: 4783

Based on what you included in your question you can get the value of the value attribute using this code:

from bs4 import BeautifulSoup 

html = """<option value="1129070-040" data-size="US9.5" data-stock="In_Stock" data-morecomingsoon="true">"""    
soup = BeautifulSoup(html,"lxml")    
value = soup.find("option")["value"]

print(value)

hope this helps

Upvotes: 1

Related Questions