【发布时间】:2020-06-06 06:48:08
【问题描述】:
我正在尝试抓取新闻评论。我想从这个蓝线 HTML 代码中抓取文本“72”
所以,这是我的代码
per_male = driver.find_element_by_css_selector('div.u_cbox_chart_progress u_cbox_chart_male >
span.u_cbox_chart_per')
print('per_male : ' + per_male.get_attribute('text'))
但是我有这个错误
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"div.u_cbox_chart_progress u_cbox_chart_male > span.u_cbox_chart_per"}
(Session info: chrome=83.0.4103.97)
我也用这个代码
per_male = driver.find_element_by_css_selector('div.u_cbox_chart_progress u_cbox_chart_male >
span.u_cbox_chart_per')
print('per_male : ' + per_male.text)
但我有同样的错误,我该如何解决这个问题?
谢谢。
【问题讨论】:
-
请使用实际的 html 而不是图像来编辑您的问题。
标签: python-3.x selenium-webdriver xpath css-selectors webdriverwait