我正试图从下面的链接抓取数据:
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