Reputation: 95
Actually, I scrape asin on amazon webpage with this code:
asin = WebDriverWait(driver, 5).until(EC.presence_of_element_located((By.ID, "averageCustomerReviews"))).get_attribute("data-asin")
But i have a problem: when the product has not customer reviews, i get an error with this code: timeout, asin not found
. I want to scrape asin on this part of page source code, for example:
https://www.amazon.fr/dp/B08HNBD7XX
Anyone know how to make for to scrape asin on this part of source code please?
Upvotes: 2
Views: 280
Reputation: 193108
Wrap up your code block in a try-except{}
inducing WebDriverWait for the visibility_of_element_located() and you can use either of the following Locator Strategy:
try:
asin = WebDriverWait(driver, 5).until(EC.visibility_of_element_located((By.ID, "averageCustomerReviews"))).get_attribute("data-asin")
print("data-asin attribute was found")
continue
except TimeoutException:
print("data-asin attribute wasn't found")
continue
Upvotes: 1