【问题标题】:Python: how to click a button in a web page using python? [closed]Python:如何使用python单击网页中的按钮? [关闭]
【发布时间】:2016-04-02 22:49:48
【问题描述】:

您可以在下面看到对照组的屏幕截图。如何使用 python 单击此区域?

【问题讨论】:

  • 欢迎来到 SO。你都尝试了些什么?请向我们提供您尝试过的相关代码,以及您所期望的和出了什么问题的解释。添加您收到的任何相关错误消息。要了解如何编写一个好问题,请阅读以下内容:stackoverflow.com/help/how-to-ask
  • @Sach.bud 我的答案适合你吗?

标签: javascript python html css


【解决方案1】:

要使用 python 单击此区域,您需要使用 Python 绑定 Selenium。使用下一个url to install iturl of how to use it。熟悉了上面的url提供的内容后,创建点击按钮的脚本应该是没有问题的。

安装 selenium 后,单击该按钮的代码将与以下代码非常相似:

from selenium import webdriver

driver = webdriver.Firefox()
# Go to your page url
driver.get('your page url')
# Get button you are going to click by its id ( also you could us find_element_by_css_selector to get element by css selector)
button_element = driver.find_element_by_id('button id')
button_element.click()

【讨论】:

  • 您好 Andriy,使用您的脚本我遇到了以下错误。请建议。 /c/Python/Python36/Scripts/python.py:第 1 行:来自:找不到命令 /c/Python/Python36/Scripts/python.py:第 3 行:意外标记附近的语法错误 (' /c/Python/Python36/Scripts/python.py: line 3: driver = webdriver.Firefox ()'
  • 实用,你应该安装gekko驱动才能使用firefox
猜你喜欢
  • 2022-01-14
  • 1970-01-01
  • 2016-09-20
  • 2021-06-23
  • 2022-11-20
  • 1970-01-01
  • 2015-03-08
  • 2019-10-02
  • 1970-01-01
相关资源
最近更新 更多