python-2.7 - 如何获取产品名称的 xpath 作为超链接
问题描述
我正在尝试从以下链接获取数据抓取:
https://www.amazon.co.uk/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=887961316995
但无法获取产品名称的 xpath(您可以通过单击 url 进行检查)。因为它是超链接,所以没有在self.hasxapth中编写什么代码?
if self.hasXpath('//[@id="result_0"]/div/div/div/div[2]/div[1]/div[1]/a'):
self.browser.find_element_by_link_text("Barbie Star Light Adventure Galaxy Dog Figure, Pink").click()
if self.hasXpath("//*[@id='productDescription']"):
description_list = self.browser.find_elements_by_xpath("//*[@id='productDescription']")
description = []
for curr_description in description_list:
if curr_description.text.encode('ascii','ignore').strip()!="":
description.append(curr_description.text.encode('ascii','ignore').strip())
description_string = "|".join(description)
product_dict['Product Description']=description_string
print product_dict
解决方案
通过使用以下 xpath,您可以获得产品名称。如果找到多个元素,则创建一个元素列表,然后获取每个元素的文本
xpath : "//ul[@id='s-results-list-atf']//a[contains(@class,'s-access-detail-page')]"
推荐阅读
- javascript - 为什么我的弹出窗口在重新加载后会在卸载前丢失其事件?
- java - 从特定日期从 Firebase 数据库查询
- html - 端口转发期间网络加载时间会增加吗?
- android - 带有 Xamarin 跨平台应用程序的 NLog 不记录任何内容
- nfc - 使用 C# 使用 OMNIKEY 5426G2 阅读器访问 NFC 标签上的所有字节时出现问题以发送 PC/SC 命令
- javascript - React (Material UI) - 组件中的表单问题
- php - 在 Laravel 中,我无法检索上传的图像。我创建了存储链接。但它不会工作。我错过了什么吗?
- javascript - AWS lambda函数有时会在连接S3 SDK时超时而没有任何错误消息
- postgresql - DB Where 条件基于 2 列的字母比较
- android - Android ffmpeg 二进制和其他 .so 文件执行错误