我无法从一个站点找到特定链接

时间:2021-03-15 13:48:12

标签: python selenium selenium-webdriver

是的,我想拉出所有引导我参加抽奖活动的链接

raffle link location

我知道查找所需链接的命令是什么。

elems = chrome.find_elements_by_xpath("//a[@href]")
for elem in elems:
    print(elem.get_attribute("href"))

问题是它也能找到我不需要的东西。

poop

是否有命令只在类名为“raffle-name”的元素中搜索这些链接

2 个答案:

答案 0 :(得分:2)

elems = chrome.find_elements_by_xpath("//div[@class='raffle-name']/a[@href]")
for elem in elems:
    print(elem.get_attribute("href"))

使用上面的xpath

答案 1 :(得分:1)

使用正则表达式,例如:

Xpath=//a[starts-with(@href,'raffles')]

或包含。在 https://www.guru99.com/using-contains-sbiling-ancestor-to-find-element-in-selenium.html

上了解更多信息