Beispiel #1
0
    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])
Beispiel #2
0
    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 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 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])
    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)
    ml_products['images'] = get_images(ml_boxes, Mercado_Libre)
    ml_products['urls'] = get_products_urls(ml_boxes, Mercado_Libre)
    ml_products['prices'] = get_price(country, ml_boxes, Mercado_Libre.price)

    cheapest_idx = cheapest(ml_products['prices'])