0

I am trying to get the link under a button ('Click Here To Play') on a webpage:

enter image description here

This is the page inspect in Chrome.

enter image description here

I am trying to get the highlighted "href" from <a href="https://vidtodo.com/.... This is my code:

from selenium import webdriver
url = 'https://www1.swatchseries.to/freecale.html?r=qepyJmjdCI6Ilo2SWFPdlk51dDBoMSmtxeHFnWXBbVOEJrcVdVMXhPT2t0bUZEZzNtNEd5ZVhCNHYrWnZkT0NZYzdZaWpmZlB0alEiLCJpdiI6IjFmYTdhMzZjYjJhODc1ZmIxODQ4MzVhZDc2N2MyYjNiIiwicyI6Ijc2NTZiMDg0MDFhNmQ1NjYifQ=='
driver = webdriver.Chrome('drivers/chromedriver.exe')
driver.maximize_window()
driver.get(url)
elements = driver.find_elements_by_xpath('/html/body/div[2]/div[2]/div/div[2]/div/div/div/div/div/div/div/div[2]/a')
for element in elements:
    print(element.get_attribute('href'))

However, I am getting this as result, rather than the link I want:

http://www1.swatchseries.to/

Process finished with exit code 0

Any suggestions on how to get the link I need?

2
  • streamplay.to/ojbcl410357t I got this. Commented Oct 6, 2020 at 8:21
  • Hi @arundeepchohan how did you get that? Please post it as an answer, as it's what I am looking for. Commented Oct 6, 2020 at 8:36

2 Answers 2

1

To get link from the Click Here To Play button you need to

Induce WebDriverWait() and wait for visibility_of_element_located() and you can use any of the following locator.

XPATH:

print(WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.XPATH,"//a[text()='Click Here to Play']"))).get_attribute("href"))

Css Selector:

print(WebDriverWait(driver,10).until(EC.visibility_of_element_located((By.CSS_SELECTOR,"a.push_button.blue"))).get_attribute("href"))

Import below libraries.

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Sign up to request clarification or add additional context in comments.

Comments

0

It seems that a script is dynamically changing the link target (the script is right above the link). It is likely that you're getting the link too early and this shows the placeholder you get.

Try waiting a few seconds, e.g. time.sleep(5) and see if that changes the link URL. If that is the case, a proper solution would be a while loop checking against the placeholder link, and waiting for it to change to the actual URL.

Comments

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.