您能否告诉我如何改进以下脚本以实际单击导出按钮。
以下脚本将转到报表页面,但不单击导出按钮:
from selenium import webdriver
options = webdriver.ChromeOptions()
options.add_argument("<Path to Chrome profile>") #Path to your chrome profile
url = '<URL of the report>'
driver = webdriver.Chrome(executable_path="C:/tools/selenium/chromedriver.exe", chrome_options=options)
driver.get(url)
exportButton = driver.find_element_by_xpath('//*[@id="js_2o"]')
clickexport = exportButton.click()
您将如何使脚本实际单击导出按钮?
我将不胜感激你的帮助。 谢谢!
尝试使用xpath,例如:
driver.find_element_by_xpath('//button[@id="export_button"]').click()
硒不是为此而设计的。 您真的关心使用Selenium和浏览器,还是只想要文件? 如果是后者,请使用requests
. 您可以使用浏览器网络检查器,右键单击>"复制为 curl"来获取所需的所有标头和 cookie。