Last active
March 19, 2020 20:22
-
-
Save spookyahell/85597ccf39dedfca85ac80e2446d6624 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| url = 'https://www.amazon.com/Dr-Seuss-Hats-Collectors-Blu-ray/dp/B00A44ZJE4/' | |
| offer_listing_url = 'https://www.amazon.com/gp/offer-listing/{asin}/' | |
| import re | |
| import requests | |
| import bs4 | |
| def replace(input, to_be_replaced, replace_with): | |
| if type(to_be_replaced) == str: | |
| return input.replace(to_be_replaced, replace_with) | |
| elif type(to_be_replaced) == list: | |
| for item in to_be_replaced: | |
| for i in range(0,99): | |
| input = input.replace(item, replace_with) | |
| return input | |
| UA = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3955.1 Safari/537.36'} | |
| x = re.fullmatch('https://www.amazon.com/([^/]+/)?dp/([^/]+)/?.+?', url) | |
| if not x: | |
| print('ASIN of product not found') | |
| asin = x.group(2) | |
| offer_listing_u = offer_listing_url.format(asin=asin) | |
| print(offer_listing_u) | |
| r = requests.get(offer_listing_u, headers = UA) | |
| text = re.search('(<a id=\'nav-top\'.+)', r.text, flags = re.DOTALL) | |
| text_res = text.group(1) | |
| #~ exit() | |
| #~ with open('AmazonHTML.html','w', encoding = 'utf-8-sig') as f: | |
| #~ f.write(text) | |
| soup = bs4.BeautifulSoup(text_res, 'html.parser') | |
| offer_list = soup.find('div', id='olpOfferList') | |
| offer_list_divs = offer_list.find_all('div') | |
| offer_divs = [] | |
| for div in offer_list_divs: | |
| class_ = div.get('class') | |
| if class_: | |
| if 'olpOffer' in class_: | |
| offer_divs.append(div) | |
| for idx, div in enumerate(offer_divs): | |
| print(f'Offer #{idx+1} | Price:') | |
| priceC = div.find('div', class_ = 'olpPriceColumn') | |
| priceOffer = priceC.find('span', class_ = 'olpOfferPrice') | |
| shippingPrice = priceC.find('span', class_='olpShippingPrice') | |
| print(priceOffer.text.strip(), end = ' ', flush = True) | |
| if shippingPrice: | |
| print('+', shippingPrice.text.strip() , 'shipping') | |
| print() | |
| conditionC = div.find('div', class_ = 'olpConditionColumn') | |
| condition = div.find('span', class_ = 'olpCondition') | |
| condition_str = replace(condition.text.strip(),['\n',' '],' ') | |
| #~ print([condition_str]) | |
| conditioncomments = conditionC.find_all('div', class_ = 'comments') | |
| if len(conditioncomments) > 0: | |
| conditioncomments = conditioncomments[1] | |
| conditioncomments_str = conditioncomments.text.strip() | |
| print(f'Condition:\n{condition_str} | No comments. / N/A\n') | |
| else: | |
| print(f'Condition:\n{condition_str} | {conditioncomments_str}\n') | |
| deliveryC = div.find('div', class_ = 'olpDeliveryColumn') | |
| shipsFrom = deliveryC.find(string=re.compile('Ships from')) | |
| print(shipsFrom.strip()) | |
| print() | |
| sellerC = div.find('div', class_ = 'olpSellerColumn') | |
| sellername = sellerC.find('h3', class_= 'olpSellerName').text.strip() | |
| rating = sellerC.find('p').text.strip() | |
| print(f'Seller:\n{sellername} - {rating}') | |
| print() | |
| print() | |
| #~ exit() | |
| #~ if shippingPrice: | |
| #~ print( | |
| #~ offer_div_divs = div.find_all('div') | |
| #~ for div in offer_div_divs: | |
| #~ print(div.get('class')) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| https://www.amazon.com/gp/offer-listing/B00A44ZJE4/ | |
| Offer #1 | Price: | |
| $66.41 + $3.99 shipping | |
| Condition: | |
| Used - Like New | No comments. / N/A | |
| Ships from NJ, United States. | |
| Seller: | |
| Go_Peachy - 5 out of 5 stars | |
| 97% positive over the past 12 months. (119,482 total ratings) | |
| Offer #2 | Price: | |
| $66.42 + $3.99 shipping | |
| Condition: | |
| Used - Good | No comments. / N/A | |
| Ships from TX, United States. | |
| Seller: | |
| HPB-Movies - 5 out of 5 stars | |
| 97% positive over the past 12 months. (34,777 total ratings) | |
| Offer #3 | Price: | |
| $66.42 + $3.99 shipping | |
| Condition: | |
| Used - Good | No comments. / N/A | |
| Ships from TX, United States. | |
| Seller: | |
| HPB-Movies - 5 out of 5 stars | |
| 97% positive over the past 12 months. (34,777 total ratings) | |
| Offer #4 | Price: | |
| $79.99 + $3.49 shipping | |
| Condition: | |
| New | Connecting viewers with great movies since 1972. All used discs are inspected and guaranteed. Used discs may not include digital copies. Customer service is our top priority! | |
| Ships from MO, United States. | |
| Seller: | |
| twilight cinema - 5 out of 5 stars | |
| 99% positive over the past 12 months. (1,528 total ratings) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment