【问题标题】:Web scraping Fidelity.com using Python and Selenium can't click button使用 Python 和 Selenium 抓取 Fidelity.com 的网页无法单击按钮
【发布时间】:2021-06-19 06:37:24
【问题描述】:

我已经开始使用 Selenium 在 Python 中创建一个脚本,以在 Fidelity.com 上抓取我的帐户 我可以登录并点击网页上的一些按钮,但是下面的按钮代码有问题。

下载 = driver.find_element_by_xpath("//button[@id='posweb-share-button']") 下载.click()

这里是html:

<button id="posweb-share-button" class="posweb-share-button pvd-btn btn-anchor posweb-metrics" type="button" aria-label="Download and Print Positions data" data-metrics="shareIcon" aria-describedby="posweb-share-popover"><pvd-icon icon="share" label="Download and Print" aria-hidden="true"></pvd-icon></button>

登录代码工作找到,我要使用代码点击网页上的其他按钮,但上面的代码没有任何反应,我得到“进程完成,退出代码0”。

【问题讨论】:

  • 你为什么把“下载”放在定位器之后,点击之前?
  • 下载只是我使用的一个变量。

标签: python selenium web-scraping


【解决方案1】:

如果您将其存储为变量,则需要像这样分隔代码:

Download = driver.find_element_by_xpath("//button[@id='posweb-share-button']")
Download.click()

【讨论】:

  • 它在 Python 中的 2 行。当我将它粘贴到原始消息中时,它的格式不正确。对不起。
  • 啊,好的。是富达主页上的那个按钮吗?或者别的地方?你的代码对我来说看起来不错,但如果不知道按钮的位置就很难确定
  • 这是我登录 Fidelity 后启动的 Python 脚本。 driver.implicitly_wait(10) driver.find_element_by_link_text("账户仓位").click() driver.implicitly_wait(10) 红利= driver.find_element_by_xpath("//button[@id='posweb-dividend-view-button']" ) Dividend.click() driver.implicitly_wait(10) 下载 = driver.find_element_by_xpath("//button[@id='posweb-share-button']") 下载.click()
  • 抱歉格式化。它在 Python 中看起来好多了。 “Dividend.click”生效后,不会点击下一步按钮。
  • 我没有 Fidelity 帐户,因此在这种情况下我无法提供帮助。也许用这些细节更新 OP,其他人可以插话。你原来的选择器在我看来很好,所以不知道你为什么会遇到问题
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2020-06-12
  • 1970-01-01
  • 1970-01-01
  • 2021-09-11
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多