我正在从URL中提取一些数据
https://blinkit.com/prn/catch-cumin-seedsjeera-whole/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())
如何根据span标记内的文本提取div内的文本?