Python + Selenium从滚动框中选择href

时间:2018-11-28 22:10:32

标签: python selenium selenium-webdriver

另一个位置问题。自从现在以来,我重新尊重了那些竭尽全力做到这一点的人,因为我看到您需要做很多事才能进行第一次,也许第二次尝试。我(和您)先前的方法再次无效。 Target page和标签,我需要href。

<figure itemprop="associatedMedia" itemscope="" itemtype="http://schema.org/ImageObject">
    <a href="https://hasznaltauto.medija.hu/9250/13704508_1.jpg" itemprop="contentUrl" data-size="640x480">

这些都不让我到我想要的地方。

find_elements_by_css_selector('figure > a')
find_elements_by_xpath("//figure[@imageprop='associatedMedia']/a[1]")

1 个答案:

答案 0 :(得分:1)

这应该有效

driver.find_element_by_xpath("//*[@id='kepek-holder']/figure[1]/a").get_attribute('href')

在chrome中,您实际上可以使用开发人员工具找到诸如this之类的任何元素的xpath。

JFYI:find_elements..方法将返回结果数组(即使单个匹配),因此您必须对输出进行索引才能使用该元素。