python-3.x - Selenium Python 返回异常数据
问题描述
我正在尝试从以下标签中提取 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")>
注意:这只是输出的一部分(前三行)
这些应该是 a 标签的 href
解决方案
只是 l 返回浏览器找到的对象你必须指定你想要的对象的哪一部分
for l in links:
print(l.get_attribute("href"))
推荐阅读
- tsql - 为什么 T-SQL TRY/CATCH 如此有限?
- sql - 有没有办法查看 SQL 表达式的类型?
- fastlane - Fastlane 插件应用中心给出提供的 app_name: 'helloworldtest" 格式无效
- windows - 如何将图标添加到 dotnet 桌面(Windows)应用程序?
- python - SyntaxError:无效的语法 - 使用 celery 时从可迭代中产生
- arrays - 写入时间长,使用 Dask 从 hdf5 文件到 numpy 堆栈的读取时间短
- c# - Android 9.0 Xamarin Android 上的服务
- css - 如何将存储在symfony公用文件夹外部的css链接到twig
- python - Flask 应用程序中可能的循环导入问题
- flutter - Flutter 可以选择在小部件树中包含/排除父小部件