[英]How to extract value in specific html code
I need your help another time, so i want to get the value for each size (Small, Medium. Large) from this portion of hmtl.下次我需要你的帮助,所以我想从 hmtl 的这一部分获取每种尺寸(小、中、大)的值。 I tried with bs4 but the output is empty.
我尝试使用 bs4 但 output 是空的。
Here's the portion of hmtl code i'm interessed in.这是我感兴趣的 hmtl 代码部分。
<select name="size" id="size">
<option value="72237">Small</option>
<option value="72238">Medium</option>
<option value="72239">Large</option>
</select>
And here my code:这里是我的代码:
html_content = requests.get(product_link).text
soupa = BeautifulSoup(html_content, "lxml")
print(soupa.option)
So thank you everyone for your help所以谢谢大家的帮助
Try this:尝试这个:
from bs4 import BeautifulSoup
import requests
url = 'yoururl.com'
r = requests.get(url)
soup = BeautifulSoup(r.content,"lxml")
options = soup.find_all("option")
option1 = options[0]
option2 = options[1]
option3 = options[2]
value1 = option1['value']
value2= option2['value']
value3 = option3['value']
print(value1,value2,value3)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.