我想要做的是解析来自"访问网站的网址"链接
https://www.truelocal.com.au/business/index-partners/canberra
来源如下:
<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>
(我认为这是Angular?)
点击链接时,新标签会打开网址
我无法在源代码中看到解析它的网址(使用Python和Selenium)
有没有办法使用Python&amp;硒? ,
答案 0 :(得分:1)
代码:
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