Reputation: 21
I am trying to get data scrape from below link:
https://www.amazon.co.uk/s/ref=nb_sb_noss?url=search-alias%3Daps&field-keywords=887961316995
But not able to get the xpath for the product name (you can check by clicking over the url). As it is hyperlink, so not getting what to code in 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
Upvotes: 0
Views: 338
Reputation: 388
Page you mentioned is using h5 tag for the product name. You can use the following locator:
driver.find_element_by_tag_name('h5');
Upvotes: 0
Reputation: 392
With the use of following xpath you can get the product name. If multiple elements are found then create a list of elements and then get text for each element
xpath: "//ul[@id='s-results-list-atf']//a[contains(@class,'s-access-detail-page')]"
Upvotes: 1