在Selenium/Python中循环遍历标记内部的标记

在Selenium/Python中循环遍历标记内部的标记,python,html,selenium,xpath,element,Python,Html,Selenium,Xpath,Element,我正在尝试使用selenium在网页上循环浏览一个属性列表,并返回属性地址和拍卖时间。到目前为止,我已经为下面的网页编写了以下python代码和html 我可以返回列表中每个属性的链接,但无法从H4标记返回所需的值。我想我在通过Xpath获取元素方面出了点问题,但我似乎无法理解 任何帮助都将不胜感激 HTML: 输出: propertyAddress = propertyLink.get_element_by_xpath('//h4[1]') AttributeError: 'WebElemen

我正在尝试使用selenium在网页上循环浏览一个属性列表,并返回属性地址和拍卖时间。到目前为止,我已经为下面的网页编写了以下python代码和html

我可以返回列表中每个属性的链接,但无法从H4标记返回所需的值。我想我在通过Xpath获取元素方面出了点问题,但我似乎无法理解

任何帮助都将不胜感激

HTML:

输出:

propertyAddress = propertyLink.get_element_by_xpath('//h4[1]')
AttributeError: 'WebElement' object has no attribute 'get_element_by_xpath'

错误似乎是您使用的是get\u元素\u by\u xpath,这不是一个有效的方法。在此之前,您在代码中使用了find_elements_by_xpath,要查找所查找的元素,只需使用只查找单个元素的方法:find_element_by_xpath

propertyList = browser.find_elements_by_xpath('//div[@data-elm-id="asset_list_content"]')

for element in propertyList:
    propertyLinks = element.find_elements_by_tag_name('a')
    for propertyLink in propertyLinks:
        propertyAddress = propertyLink.get_element_by_xpath('//h4[1]')
        propertyAuctionTime = propertyLink.get_element_by_xpath('//h4[2]')
        print(propertyAddress).text
        print(propertyAuctionTime).text
propertyAddress = propertyLink.get_element_by_xpath('//h4[1]')
AttributeError: 'WebElement' object has no attribute 'get_element_by_xpath'