Search code examples
pythonselenium-webdriverweb-scrapingwebdriver

Scrap asin on amazon webpage with python and selenium


Anyone know how to make for to scrap asin on this part of source code please? Asin is always in same part of sourcecode on webpage product.

enter image description here

I've try:

asin_n = WebDriverWait(driver,5).until(EC.presence_of_element_located((By.XPATH, "(//td[@class='.prodDetAttrValue'])"))).text 

And

asin_n = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "(//td[@class='.prodDetAttrValue'])"))).text

And

asin_n = WebDriverWait(driver,20).until(EC.visibility_of_element_located((By.XPATH, "//td[@class='a-size-base prodDetAttrValue']"))).text                

And

asin_n = driver.find_element_by_css_selector('td.a-size-base.prodDetAttrValue').text

But not work, anyone know how to make for scrap asin on this part please? Thanks for reply, bye!


Solution

  • prodDetAttrValue is one of the classname but there are other classnames as well. So you need to use contains() instead and you can use either of the following Locator Strategies:

    • Using XPATH and prodDetAttrValue class:

      asin_n = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//th[contains(., 'ASIN')]//following::td[contains(@class, 'prodDetAttrValue')]"))).text
      
    • Using XPATH and complete class:

      asin_n = WebDriverWait(driver, 20).until(EC.visibility_of_element_located((By.XPATH, "//th[contains(., 'ASIN')]//following::td[@class='a-size-base prodDetAttrValue']"))).text