Jump to content

Bruno amoedo

Members
  • Content Count

    2
  • Joined

  • Last visited

Everything posted by Bruno amoedo

  1. Bruno amoedo

    Error importing a library

    So, i'm trying to run this python code but without sucess can anyone helpe me ? only the bs4 library of the problem this is python code: import bs4 import requests import pandas as pd def main(): proxies={ "http": "", "https": "" } keyword = input('\nKeyword: ') zipCode = input('\nZip Code: ') name = [] barCode = [] price = [] issue = [] address = [] distance = [] session = requests.Session() r = session.get('https://precodahora.ba.gov.br/produtos/', proxies=proxies) cookie = session.cookies.get_dict() soup = bs4.BeautifulSoup(r.text, features='lxml') csrf_token = soup.select_one('meta[id="validate"]')['data-id'] headers = { 'X-CSRFToken': csrf_token, 'X-Requested-With': 'XMLHttpRequest' } locPayload = { 'cep': zipCode } try: locRes = session.post('https://precodahora.ba.gov.br/geolocation/', proxies=proxies, headers=headers, cookies=cookie, data=locPayload).json() if locRes['codigo'] == 80: lat = locRes['lat'] lon = locRes['lon'] pagina = 1 while True: proPayload = { 'termo': keyword, 'horas': 24, 'latitude': lat, 'longitude': lon, 'raio': 1, 'pagina': pagina, 'ordenar': 'preco.desc', } proRes = session.post('https://precodahora.ba.gov.br/produtos/', proxies=proxies, headers=headers, cookies=cookie, data=proPayload).json() if proRes['codigo'] == 80: products = proRes['resultado'] for i, product in enumerate(products): name.append(product['produto']['descricao']) barCode.append(product['produto']['gtin']) price.append(product['produto']['precoBruto']) issue.append(product['produto']['data']) address.append(product['estabelecimento']['endLogradouro'] + ' ' + product['estabelecimento']['endNumero'] + ' ' + product['estabelecimento']['bairro'] + ' ' + product['estabelecimento']['cep'] + ', ' + product['estabelecimento']['municipio']) distance.append(product['estabelecimento']['distancia']) pagina += 1 else: if pagina == 1: print(proRes['descricao']) break if pagina > 1: dict = {'Product Name': name,'Price': price,'Nome do estabelecimento':address,'distancia':distance} df = pd.DataFrame(dict) print("\n", df) print("\n") #df.to_csv(keyword+'.csv', encoding='utf-8-sig') else: print(locRes['descricao']) except: print('\nPlease enter your zip code correctly (*****-***)') if __name__ == '__main__': main()
  2. Bruno amoedo

    Error importing a library

    thanks, a hug from brazil for you
×