Python 使用selenium获取从附加到按钮的javascript生成的href?
我正在使用selenium从我们的电话系统(Barracuda Cudatel,非常好的小型企业系统,但它没有我需要的API)中提取一些自动电话报告。报告页面上有一个按钮,它在单击侦听器上附加了一些javascript,然后告诉浏览器下载文件 显然,selenium并不是真的设计来拉这样的文件,但是我所要做的就是获取url的href,该url将被发送到浏览器。然后,我可以将会话凭据与请求一起使用,以提取文件并对其进行处理 如何(在Python中)执行以下操作:Python 使用selenium获取从附加到按钮的javascript生成的href?,python,python-3.x,selenium,python-3.4,Python,Python 3.x,Selenium,Python 3.4,我正在使用selenium从我们的电话系统(Barracuda Cudatel,非常好的小型企业系统,但它没有我需要的API)中提取一些自动电话报告。报告页面上有一个按钮,它在单击侦听器上附加了一些javascript,然后告诉浏览器下载文件 显然,selenium并不是真的设计来拉这样的文件,但是我所要做的就是获取url的href,该url将被发送到浏览器。然后,我可以将会话凭据与请求一起使用,以提取文件并对其进行处理 如何(在Python中)执行以下操作: 查询“单击”的事件侦听器 启动ja
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from time import sleep
dcap = webdriver.DesiredCapabilities.CHROME
driver = webdriver.Remote(command_executor='http://gridurl:4444/wd/hub', desired_capabilities=dcap)
driver.get("http://cudatelurl")
driver.find_element_by_name("__auth_user").send_keys("user")
driver.find_element_by_name("__auth_pass").send_keys("password")
driver.find_element_by_id("manage").click()
driver.get("http://cudatelurl/#!/cudatel/cdrs")
sleep(5)
date_dropdown = Select(driver.find_element_by_xpath('//*[@id="cui-content-inner"]/div[3]/div/div/div/div[2]/div/div/div[1]/div[2]/div/select'))
date_dropdown.select_by_value("last_week")
# This is the element that has javascript attached to it the click register is
# button.widgetType.csvButtonWidget.widgetized.actionButtonType.table-action
# but I'd prefer to not hard code it
driver.find_element_by_xpath('//*[@id="cui-content-inner"]/div[3]/div/div/div/div[2]/div/div/div[1]/div[2]/button[1]')
print(driver.get_cookies())
print(driver.title)
sleep(10)
driver.close()
driver.quit()
您仍然可以通过为要自动下载的特定mime类型的文件配置目标目录(无需“另存为”对话框)来使用selenium进行访问,请参阅: