Python:如何通过硒使用find_element_by_css_selector

问题描述 投票:0回答:1

我正在尝试抓取新闻评论。我想从此蓝线HTML代码中检索文本“ 72”]

enter image description here

所以,这是我的代码

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)

但是我有同样的错误,如何解决这个问题?

Thx。

我正在尝试抓取新闻评论。我想从蓝线的HTML代码中检索文本“ 72”,所以这是我的代码per_male = driver.find_element_by_css_selector('div.u_cbox_chart_progress ...

python-3.x selenium-webdriver xpath css-selectors webdriverwait
1个回答
0
投票

要抓取文本72

© www.soinside.com 2019 - 2024. All rights reserved.