我正在尝试从以下标签中提取href
<a href="https://www.olx.ph/item/pioneer-pointe-condominium-unit-for-rent-1-br-fully-furnished-22k-ID8k7OP.html?h=ba76d6b70e&utm_source=Opt_Homepage_Var_1&utm_medium=Ad_Clicks&utm_campaign=Phase_2" itemprop="url" class="funnel" data-category-id="137" data-funnel-type="Select Ad" data-action-type="Select Ad" data-funnel-userid="0">
<span class="title" itemprop="name">Pioneer Pointe Condominium unit for rent - 1 BR Fully Furnished - 22K</span>
</a>
我在Selenium和python中使用以下代码:
links=browser.find_elements_by_xpath('//a[@itemprop="url"]')
for l in links:
print(l)
我当前的异常输出是:
<selenium.webdriver.remote.webelement.WebElement (session="8b6a29a1af20221f48056d6a8f34bd63", element="0.8368598264582081-1")>
<selenium.webdriver.remote.webelement.WebElement (session="8b6a29a1af20221f48056d6a8f34bd63", element="0.8368598264582081-2")>
<selenium.webdriver.remote.webelement.WebElement (session="8b6a29a1af20221f48056d6a8f34bd63", element="0.8368598264582081-3")>
注意:这只是输出的一部分(前三行)
这些应该是标签的href
答案 0 :(得分:0)
仅l返回浏览器找到的对象,您必须指定所需对象的一部分
for l in links:
print(l.get_attribute("href"))