I am testing my code using different style amazon pages and it cannot parse ones in a certain style. It works for 1 type of page but not the page where different options are presented as tabs.
import bs4, requests
header = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/41.0.2228.0 Safari/537.6',}
goodRes = requests.get('https://www.amazon.com/Automate-Boring-Stuff-Python-Programming/dp/1593275994/', headers=header)
goodRes2 = requests.get('https://www.amazon.com/gp/product/1593277954/', headers=header)
badRes = requests.get('https://www.amazon.com/Automate-Boring-Stuff-Python-Programming-ebook/dp/B00WJ049VU/', headers=header)
soup = bs4.BeautifulSoup(goodRes.text, 'lxml') # change to badRes for error
price = soup.select('.offer-price')
name = soup.select('#productTitle')
author = soup.select('.contributorNameID')
print(name[0].text.strip())
print(author[0].text.strip())
print(price[0].text.strip())
the first two URL's (goodRes & goodRes2) are direct links to ebooks, they are retrieved by get, and parsed by soup for the information I need correctly.
the third URL is the afformentioned 'tabbed' style page, even though the get request works, soup does not find anything with the given CSS selectors (even though they are exactly the same on this tabbed page). This produces a "list index out of range" error when executing the first print function.
Im not sure how to modify this in order to parse information from the badRes URL.
any help appreciated. Thanks.