简体   繁体   English

获取 href selenium python3 中的链接

[英]Get the link inside href selenium python3

I am trying to get the link href with python and selenium.我正在尝试使用 python 和 selenium 获取链接 href。 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. href 网址是<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 am using a website called https://www.mohmal.com/en/inbox to get the value inside href.我正在使用一个名为https://www.mohmal.com/en/inbox的网站来获取 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.我已经尝试使用link = driver.find_element_by_xpath("//a[contains(text(),'Verify Email')]").get_attribute('href') print(link)但它返回了网站网址而不是链接里面href。 Any help will be appreciated!任何帮助将不胜感激!

Please use this xpath :请使用此 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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