Advertisement
vinissh

novatecLivros

Oct 23rd, 2019
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.21 KB | None | 0 0
  1. import requests
  2. import time
  3. from bs4 import BeautifulSoup
  4.  
  5.  
  6. def  http_post(url,buscar_livro):
  7.     payload={
  8.         'palavra': buscar_livro,
  9.     'enviar': 'Buscar'
  10.     }
  11.  
  12.     try:
  13.         return requests.post(url,data=payload)
  14.  
  15.     except (requests.exceptions.HTTPError, requests.exceptions.RequestException,requests.exceptions.ConnectionError,requests.exceptions.Timeout) as e:
  16.         print(str(e))
  17.         pass
  18.     except Exception as e:
  19.         raise
  20.     return none
  21.  
  22. def parse_html(content):
  23.     soup = BeautifulSoup(content,'lxml')
  24.     produtos = soup.find_all('table')[10].find_all('td')
  25.  
  26.     f = open('td.html','w',encoding='utf-8')
  27.  
  28.     for produto in produtos:
  29.         f.write(str(produto))
  30.         f.write('\n\n\n')
  31.     f.close()
  32.  
  33.     '''
  34.    lista_produtos = []
  35.    for produtos in produtos:
  36.        for string in produtos.stripped_strings:
  37.            if(string == 'Esgotado'):
  38.                continue
  39.            lista_produtos.append(string)
  40.        print(lista_produtos)
  41.     '''
  42.  
  43.  
  44.    
  45.  
  46. if __name__ == '__main__':
  47.     url =  "https://novatec.com.br/busca.php"
  48.     buscar_livro =  "Pentest"
  49.     r = http_post(url,buscar_livro)
  50.     if r:
  51.         parse_html(r.text)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement