html div标签就是这样的
<div class="_1vC4OE _37U4_g">
₹
<!-- -->
15,190
</div>
我想提取数字15,190。 我写的代码是这样的
from selenium import webdriver
driver = webdriver.Chrome()
url = 'required url'
driver.get(url)
elem = driver.find_element_by_css_selector('div._37U4_g')
price = elem.get_attribute('value')
print('price of the item is:', price)
driver.close()
但它返回None。提前谢谢!
答案 0 :(得分:0)
试试这个
from selenium import webdriver
driver = webdriver.Chrome()
url = 'required url'
driver.get(url)
elem = driver.find_element_by_css_selector('div._37U4_g')
price = elem.text
print('price of the item is:', price)
driver.close()
您的代码不会返回任何内容,因为您发布的HTML中没有attribute
名为value
。
如果HTML像这样
,您的代码将得到正确的输出<div class="_1vC4OE _37U4_g" value = "₹15,190></div>