python - 如何使用 Python 和 BeautifulSoup 在此页面上选择 87%
问题描述
我正在尝试从此页面中抓取一些数据。
https://www.australiacouncil.gov.au/research/electorate-profiles/wright/#!Wright
问题是我无法使用 BeautifulSoup 和 Python 获得 87%。
当我运行时:
soup.find("div",{"class":"progress-bar-item progress-bar-item--text "})
我得到 {{perc}} 而不是实际数字。
解决方案
它看起来确实是动态构造的。如果沿着硒路线走,您可以执行以下操作:
from selenium import webdriver
d = webdriver.Chrome(r'path\chromedriver.exe')
d.get('https://www.australiacouncil.gov.au/research/electorate-profiles/wright/#!Wright')
print(d.find_element_by_css_selector('.dzs-progress-bar strong').text)
d.quit()
推荐阅读
- asp.net-core - 如何安全地生成外部链接?
- android - 无法在微信上分享
- arrays - 在功能组件中映射数组
- python - Django - 文件字段未显示所选文件名
- reactjs - 反应,链接中道具“组件”的值无效
- c++ - 有没有办法让编译器在我放置字符串而不是 nlohmann::json 对象时抛出错误?
- swift - 允许用户在 macCatalyst 中自定义 Touch Bar
- delphi - 屏幕调整大小delphi后如何在运行时处理组件的重新对齐
- ruby-on-rails - 使用 capybara 设计登录验收测试
- arrays - Translate Array with Array