-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscraping.py
40 lines (29 loc) · 2.1 KB
/
scraping.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import requests
import re
from bs4 import BeautifulSoup as bs
soda_price = requests.get('http://0.0.0.0:8000/get_cheaper_soda/').json()
alcohol_price = requests.get('http://0.0.0.0:8000/get_cheaper_alcohol_ml/').json()
internet_soda_price = soda_price['item_price']/soda_price['item_volume']
internet_alcohol_price = alcohol_price['item_price']/alcohol_price['item_volume']
print(internet_alcohol_price)
print(internet_soda_price)
# lojas_americanas_url = requests.get("https://www.americanas.com.br/busca/detergente-liquido")
# soup = bs(lojas_americanas_url.content, 'html.parser')
# product_list = soup.select("div.product-grid-item > div:nth-child(1)")
# cheaper_product = {'item_description':'','item_volume':1, 'item_price':100}
# for item in product_list:
# item_name = item.get('name')
# item_volume = None
# if item.select_one("div.product-grid-item > div:nth-child(1) > div:nth-child(2) > a:nth-child(1) > section:nth-child(1) > div:nth-child(3) > div:nth-child(2) > div:nth-child(3) > span:nth-child(1)"):
# item_price = float(re.search(r'R\$\s*(\d{1,5}\,\d{1,2})', item.select_one("div.product-grid-item > div:nth-child(1) > div:nth-child(2) > a:nth-child(1) > section:nth-child(1) > div:nth-child(3) > div:nth-child(2) > div:nth-child(3) > span:nth-child(1)").text).group(1).replace(',','.'))
# if re.search(r'((\d{1,4})\s*(ml|ML|Ml|Litros|litros|L|l))', item_name):
# if re.search(r'((\d{1,4})\s*(ml|ML|Ml|Litros|litros|L|l))', item_name).group(3) in ['Litros','litros','L','l']:
# item_volume = float(re.search(
# r'((\d{1,4})\s*(ml|ML|Ml|Litros|litros|L|l))', item_name).group(2))*1000
# else:
# item_volume = float(re.search(r'((\d{1,4})\s*(ml|ML|Ml|Litros|litros|L|l))', item_name).group(2))
# if (item_name and item_price and item_volume) and ((item_price/item_volume) < (cheaper_product['item_price']/cheaper_product['item_volume'])):
# cheaper_product['item_description'] = item_name
# cheaper_product['item_volume'] = item_volume
# cheaper_product['item_price'] = item_price
# print(cheaper_product)