Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/385.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用selenium:Python从onclick javascript提取url_Javascript_Python_Selenium_Web Scraping - Fatal编程技术网

如何使用selenium:Python从onclick javascript提取url

如何使用selenium:Python从onclick javascript提取url,javascript,python,selenium,web-scraping,Javascript,Python,Selenium,Web Scraping,从包含以下代码的页面(可以在inspect元素中看到,而不是在源代码中看到): 你也可以直接下载 我想提取href链接。但是driver.page\u source不起作用,因为它是脚本的一部分,所以如果不是源代码,那么我需要从哪里准确提取,这里的xpath具体是什么 此外,如果可能的话,此页面会触发文件下载(下载链接为-“”),因此如果可以捕获此链接,那么这将解决我的问题。首先,要查找链接元素,请使用此xpath- //p[@id = 'download_sub_text']/a 然后

从包含以下代码的页面(可以在inspect元素中看到,而不是在源代码中看到):


你也可以直接下载

我想提取href链接。但是
driver.page\u source
不起作用,因为它是脚本的一部分,所以如果不是源代码,那么我需要从哪里准确提取,这里的xpath具体是什么


此外,如果可能的话,此页面会触发文件下载(下载链接为-“”),因此如果可以捕获此链接,那么这将解决我的问题。

首先,要查找链接元素,请使用此xpath-

//p[@id = 'download_sub_text']/a
然后,要获取属性值,可以使用
get\u attribute()
方法。获取元素的
href
属性的值-

required_url = driver.find_element_by_xpath("//p[@id = 'download_sub_text']/a").get_attribute("href")
print(required_url)
此外,如果您想在单击后获取它重定向到的链接,您可以在单击按钮后获取
当前\u url
-

required_button = driver.find_element_by_xpath("//p[@id = 'download_sub_text']/a")
required_button.click()
required_url = driver.current_url

你能提供实际的url吗?你能不点击就提出解决方案吗?
required_button = driver.find_element_by_xpath("//p[@id = 'download_sub_text']/a")
required_button.click()
required_url = driver.current_url