def test_products_info_getters(self): user_request = 'audifonos inalambricos' country = 'mx' for Page in self.Pages: page_url = Page.adapt_url(Page, user_request, country) page_soup = extract_soup(page_url, 1, just_soup=True) page_boxes = search_boxes(page_soup, Page.boxes) #New test page_names = len(get_names(page_boxes, Page)) page_images = len(get_images(page_boxes, Page)) page_urls = len(get_products_urls(page_boxes, Page)) page_price = len(get_price(country, page_boxes, Page)) trials = [page_names, page_images, page_urls, page_price] for test in trials: self.assertEqual(len(page_boxes), test)
def test_cheapest_gets_info(self): user_request = 'audifonos inalambricos' country = 'mx' ebay_url = Ebay.adapt_url(Ebay, user_request, country) ebay_soup = extract_soup(ebay_url, 1, just_soup=True) ebay_boxes = search_boxes(ebay_soup, Ebay.boxes) ebay_prices = get_price(country, ebay_boxes, Ebay.price) ebay_cheapest_idx, ebay_cheapest_price = cheapest( ebay_prices, position_and_price=True) cheapest_ebay_product_1 = get_cheapest(ebay_cheapest_idx, ebay_boxes, ebay_cheapest_price, country, Ebay) for value in cheapest_ebay_product_1: self.assertIsNotNone(cheapest_ebay_product_1[value])
def test_cheapest_gets_info(self): user_request = 'audifonos inalambricos' country = 'mx' ml_url = Mercado_Libre.adapt_url(Mercado_Libre, user_request, country) ml_soup = extract_soup(ml_url, 1, just_soup=True) ml_boxes = search_boxes(ml_soup, Mercado_Libre.boxes) meli_prices = get_price(country, ml_boxes, Mercado_Libre.price) meli_cheapest_idx, meli_cheapest_price = cheapest( meli_prices, position_and_price=True) cheapest_ml_product_1 = get_cheapest(meli_cheapest_idx, ml_boxes, meli_cheapest_price, country, Mercado_Libre) for value in cheapest_ml_product_1: self.assertIsNotNone(cheapest_ml_product_1[value])
def test_products_info_getters(self): user_request = 'audifonos inalambricos' country = 'mx' ml_url = Mercado_Libre.adapt_url(Mercado_Libre, user_request, country) ml_soup = extract_soup(ml_url, 1, just_soup=True) ml_boxes = search_boxes(ml_soup, Mercado_Libre.boxes) getters = { 'ml_names': len(get_names(ml_boxes, Mercado_Libre.name_and_images)), 'ml_images': len(get_images(ml_boxes, Mercado_Libre)), 'ml_urls': len(get_products_urls(ml_boxes, Mercado_Libre)), 'ml_price': len(get_price(country, ml_boxes, Mercado_Libre.price)), } for value in getters: self.assertEqual(len(ml_boxes), getters[value])
def scraper(Page, user_request, country): #Adapt the url url = Page.adapt_url(Page, country, user_request) #All the HTML of the page soup = extract_soup(url, 1, just_soup=True) # #HTML divided by products, and stored as elements of an array boxes = search_boxes(soup, Page.boxes) # From this part, could get better AFTER the 4 scrapers are made #From the Boxes, obtain the prices prices = get_price(country, boxes, Page.price) #Obtain the cheapest from prices and then, you obtain the cheapest product as a dictionary cheapest_idx, cheapest_price = cheapest(prices, position_and_price=True) cheapest_product_dictionary = get_cheapest(cheapest_idx, boxes, cheapest_price, country, Page) return cheapest_product_dictionary
def test_products_info_getters(self): user_request = 'audifonos inalambricos' country = 'mx' amazon_url = Amazon.adapt_url(Amazon, user_request, country) amazon_soup = extract_soup(amazon_url, 1, just_soup=True) amazon_boxes = search_boxes(amazon_soup, Amazon.boxes) amazon_names = len(get_names(amazon_boxes, Amazon.name_and_images)) amazon_images = len(get_images(amazon_boxes, Amazon)) amazon_urls = len(get_products_urls(amazon_boxes, Amazon)) amazon_price = len(get_price(country, amazon_boxes, Amazon.price)) amazon_reviews = len(get_reviews(country, amazon_boxes, Amazon.reviews)) amazon_stars = len(get_stars(country, amazon_boxes, Amazon.stars)) trials = [ amazon_names, amazon_images, amazon_urls, amazon_price, amazon_reviews, amazon_stars ] for test in trials: self.assertEqual(len(amazon_boxes), test)
def request_products(user_request, Page, header, home=False, country='mx'): page_url = Page.adapt_url(Page, user_request, country) # All the HTML of the page page_soup, status = extract_soup(page_url, header) # Wait until receive the info or been denied if status == 503: while status == 503: time.sleep(1) page_soup, status = extract_soup(page_url) elif status == 200: # HTML divided by products, and stored as elements of an array page_boxes = search_boxes(page_soup, Page.boxes) page_products = {} # Obtain the info of the product page_products['names'] = get_names(page_boxes, Page) page_products['images'] = get_images(page_boxes, Page) page_products['urls'] = get_products_urls(page_boxes, Page) page_products['prices'] = get_price(country, page_boxes, Page, home) page_products['status'] = status return page_products else: page_products = {} # With the empty values, not None, the script knows that this won't be # uploaded. In case of one 'None', it thinks that there was a product box # without info. Somethings that occurs in Amazon page_products['store'] = Page.name page_products['idx'] = Page.index page_products['product'] = user_request page_products['names'] = [] page_products['images'] = [] page_products['urls'] = [] page_products['prices'] = [] page_products['status'] = status return page_products
def scraper(user_request, country): #Adapt the url ml_url = Mercado_Libre.adapt_url(Mercado_Libre, country, user_request) #All the HTML of the page ml_soup = extract_soup(ml_url, 1, just_soup=True) # #HTML divided by products, and stored as elements of an array ml_boxes = search_boxes(ml_soup, Mercado_Libre.boxes) # From this part, could get better AFTER the 4 scrapers are made #From the Boxes, obtain the prices meli_prices = get_price(country, ml_boxes, Mercado_Libre.price) #Obtain the cheapest from prices and then, you obtain the cheapest product as a dictionary meli_cheapest_idx, meli_cheapest_price = cheapest(meli_prices, position_and_price=True) cheapest_ml_product_dictionary = get_cheapest(meli_cheapest_idx, ml_boxes, meli_cheapest_price, country, Mercado_Libre) return cheapest_ml_product_dictionary
def scraper(user_request, country): #Adapt the url amazon_url = Amazon.adapt_url(Amazon, user_request, country) #All the HTML of the page amazon_soup = extract_soup(amazon_url, 1, just_soup=True) # #HTML divided by products, and stored as elements of an array amazon_boxes = search_boxes(amazon_soup, Amazon.boxes) # From this part, could get better AFTER the 4 scrapers are made #From the Boxes, obtain the prices amazon_prices = get_price(country, amazon_boxes, Amazon.price) #Obtain the cheapest from prices and then, you obtain the cheapest product as a dictionary amazon_cheapest_idx, amazon_cheapest_price = cheapest( amazon_prices, position_and_price=True) cheapest_amazon_product_dictionary = get_cheapest(amazon_cheapest_idx, amazon_boxes, amazon_cheapest_price, country, Amazon) return cheapest_amazon_product_dictionary
amazon_soup = extract_soup(amazon_url, 1, just_soup=True) #HTML divided by products, and stored as elements of an array amazon_boxes = search_boxes(amazon_soup, Amazon.boxes) amazon_products = {} amazon_products['name'] = get_names(amazon_boxes, Amazon.name_and_images) '''Amazon's images source (link)''' amazon_products['image'] = get_images(amazon_boxes, Amazon) amazon_products['url'] = get_products_urls(amazon_boxes, Amazon) '''Just Amazon's products id. Is used as a url generator: amazon's url + domain + "/dp/" + product_id''' # amazon_products['id']= amazon_products_id(amazon_boxes) '''Just stars as float''' amazon_products['star'] = get_stars(country, amazon_boxes, Amazon.stars) '''Just number of reviews as int''' amazon_products['review'] = get_reviews(country, amazon_boxes, Amazon.reviews) amazon_products['price'] = get_price(country, amazon_boxes, Amazon.price) # print(len(amazon_reviews)) # for key in amazon_products: # print(key, ':', amazon_products[key]) cheapest = cheapest(amazon_products['price']) cheapest_amazon_product = get_cheapest(cheapest, amazon_products) for key in cheapest_amazon_product: print(key, ':', cheapest_amazon_product[key]) # for highlight in amazon_highlightners: # print(highlight)
return cheapest_product_dictionary if __name__ == "__main__": user_request = 'audifonos inalambricos' country = 'mx' ebay_url = Ebay.adapt_url(Ebay, user_request, country) #All the HTML of the page ebay_soup = extract_soup(ebay_url, 1, just_soup=True) # #HTML divided by products, and stored as elements of an array ebay_boxes = search_boxes(ebay_soup, Ebay.boxes) # print(ebay_boxes) ebay_products = {} ebay_products['names'] = get_names(ebay_boxes, Ebay.name_and_images) # #Ebay's images source (link) ebay_products['images'] = get_images(ebay_boxes, Ebay) ebay_products['urls'] = get_products_urls(ebay_boxes, Ebay) ebay_products['prices'] = get_price(country, ebay_boxes, Ebay.price) cheapest_idx = cheapest(ebay_products['prices']) cheapest_ebay_product2 = get_cheapest(cheapest_idx, ebay_products) print(f'\nTest ONE:') for key in cheapest_ebay_product2: print(key, ':', cheapest_ebay_product2[key])
return cheapest_ml_product_dictionary if __name__ == "__main__": user_request = 'audifonos inalambricos' country = 'mx' ml_url = Mercado_Libre.adapt_url(Mercado_Libre, user_request, country) #All the HTML of the page ml_soup = extract_soup(ml_url, 0, just_soup=True) # #HTML divided by products, and stored as elements of an array ml_boxes = search_boxes(ml_soup, Mercado_Libre.boxes) print(f'Test ONE:') meli_prices = get_price(country, ml_boxes, Mercado_Libre.price) meli_cheapest_idx, meli_cheapest_price = cheapest(meli_prices, position_and_price=True) cheapest_ml_product_1 = get_cheapest(meli_cheapest_idx, ml_boxes, meli_cheapest_price, country, Mercado_Libre) for key in cheapest_ml_product_1: print(key, ':', cheapest_ml_product_1[key]) # # print('boxes:', len(ml_boxes)) ml_products = {} ml_products['names'] = get_names(ml_boxes, Mercado_Libre.name_and_images) #Mercado_Libre's images source (link)