【问题标题】:How to pull out text within an h3 tag class in selenium using python?如何使用python在selenium的h3标签类中提取文本?
【发布时间】:2020-06-01 22:47:49
【问题描述】:
我目前无法从以下页面提取文本:
我试过browser.find_element_by_class_name("W6bZuc.YMllz").text
还有
browser.find_element_by_tag_name("h3").text
但这些都是空的。有没有办法在 python 中始终使用 selenium webdriver 来获取 h3 元素?谢谢。
【问题讨论】:
标签:
python-3.x
selenium
selenium-chromedriver
selenium-firefoxdriver
【解决方案1】:
尝试获取textContent
browser.find_element_by_class_name("W6bZuc.YMllz").get_attribute("textContent")
【解决方案2】:
尝试使用.get_attribute('innerHTML'):
driver.find_element_by_css_selector('.W6bZuc.YMllz').get_attribute('innerHTML')