python selenium-如何根据跨度标签中的文本提取元素?
我正在从url https://blinkit.com/prn com.com/prn-prn-prn-prn-prn/prn-prn/prn-prn/prn-prn/prn-com/prn-prn/prn-com/prn-com-com/prn一下,我正在提取一些数据/catch-cumin-seedsjeera-hole/prid/56692 带有非结构化产品详细信息元素。
使用此代码:
product_details = wd.find_elements(by=By.XPATH, value="//div[@class='ProductAttribute__ProductAttributesDescription-sc-dyoysr-2 lnLDYa']")
info_shelf_life = product_details[0].text.strip()
info_country_of_origin = product_details[1].text.strip()
如您所见,产品详细信息元素是非结构化的,当索引从URL更改为URL时,此方法不合适,
因此尝试了此方法,这会丢弃Nosuchwindowexception错误。
info_shelf_life = wd.find_element(By.XPATH,value= "//div[[contains(@class, 'ProductAttribute__ProductAttributesDescription-sc-dyoysr-2 lnLDYa') and contains(., 'Shelf Life')]/..")
print(info_shelf_life.text.strip())
如何根据跨度标签内部的文本在div中提取文本?
I am extracting some data from URLhttps://blinkit.com/prn/catch-cumin-seedsjeera-whole/prid/56692 with unstructured Product Details elements.
Using this code:
product_details = wd.find_elements(by=By.XPATH, value="//div[@class='ProductAttribute__ProductAttributesDescription-sc-dyoysr-2 lnLDYa']")
info_shelf_life = product_details[0].text.strip()
info_country_of_origin = product_details[1].text.strip()
As you can see the Product details elements are unstructured and this approach is not suitable when the Index gets changed from URL to URL
Hence tried this approach, which throws out a NoSuchWindowException error.
info_shelf_life = wd.find_element(By.XPATH,value= "//div[[contains(@class, 'ProductAttribute__ProductAttributesDescription-sc-dyoysr-2 lnLDYa') and contains(., 'Shelf Life')]/..")
print(info_shelf_life.text.strip())
How can I extract text inside div based on text inside span tags?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您的XPath无效。您可以尝试
获取所需的数据
Your XPath is invalid. You can try
to get required data