Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/22.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 WebDriver w Python从Angular JS链接提取URL_Python_Angularjs_Selenium Webdriver_Web Scraping - Fatal编程技术网

使用Selenium WebDriver w Python从Angular JS链接提取URL

使用Selenium WebDriver w Python从Angular JS链接提取URL,python,angularjs,selenium-webdriver,web-scraping,Python,Angularjs,Selenium Webdriver,Web Scraping,我想做的是解析上“访问网站”链接的URL 资料来源如下: <span class="text-frame" ng-class="(vm.getHaveSecondaryWebsites()==true) ? 'with-aditional-item':''"> <span ng-click="vm.openLink(vm.getReadableUrl(vm.getPrimaryWebsite()),'_blank')" role="button" tabindex="

我想做的是解析上“访问网站”链接的URL

资料来源如下:

<span class="text-frame" ng-class="(vm.getHaveSecondaryWebsites()==true) ? 'with-aditional-item':''">
    <span ng-click="vm.openLink(vm.getReadableUrl(vm.getPrimaryWebsite()),'_blank')" role="button" tabindex="0">Visit website</span>
</span>

访问网站
(我认为这是有角度的??)

单击链接时,“新建”选项卡将打开URL

我在源代码中看不到解析它的URL(使用Python和Selenium)

是否有一种使用Python和Selenium检索URL的方法

代码:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get('https://www.truelocal.com.au/business/index-partners/canberra')
driver.find_element_by_xpath('//span[text()="Visit website"]').click()

# Switching to the 2nd newly opened tab
driver.switch_to.window(driver.window_handles[1])
print(driver.current_url)

# Switching to the 1st tab
driver.switch_to.window(driver.window_handles[0])
print(driver.current_url)
输出:

http://www.indexpartners.com.au/
https://www.truelocal.com.au/business/index-partners/canberra

很 完美!做得好。非常感谢您的帮助@Ali