0

What I want to do is parse the URL from a "Visit Website" link on

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

Source reads as follows:

<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>

(I think that is Angular??)

When the link is clicked the new tab opens the URL

I can't see the URL in the source to parse it (using Python and Selenium)

Is there a way to retrieve the URL using Python & Selenium? ,

1 Answer 1

1

Code:

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)

Output:

http://www.indexpartners.com.au/
https://www.truelocal.com.au/business/index-partners/canberra
Sign up to request clarification or add additional context in comments.

1 Comment

Perfect! Well done. Thank you so much for your help @Ali

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.