简体   繁体   中英

Get the link inside href selenium python3

I am trying to get the link href with python and selenium. The href url is <a target="_blank" href="https://click.discord.com/ls/click?upn=RANDOMNUMBERSANDLETTERS" style="text-decoration:none;line-height:100%;background:#5865f2;color:white;font-family:Ubuntu, Helvetica, Arial, sans-serif;font-size:15px;font-weight:normal;text-transform:none;margin:0px;"> Verify Email </a> I want to get the full discord link but I have no idea how. I am using a website called https://www.mohmal.com/en/inbox to get the value inside href. I already tried using link = driver.find_element_by_xpath("//a[contains(text(),'Verify Email')]").get_attribute('href') print(link) but it returned the website url instead of the link inside href. Any help will be appreciated!

Please use this xpath :

(//a[contains(text(),'Verify Email')])[2]

In code :

link = driver.find_element_by_xpath("(//a[contains(text(),'Verify Email')])[2]").get_attribute('href')
print(link)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM