vinissh

teste_python_basico

Nov 30th, 2019
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.07 KB | None | 0 0
  1. from bs4 import  BeautifulSoup
  2. import requests
  3. import html5lib
  4. import wget
  5.  
  6. try:
  7.     pesquisaProduto = str('morotola')
  8.     requestMercadoLivre = requests.get('https://lista.mercadolivre.com.br/' + pesquisaProduto)
  9.  
  10.     with open('localizado.html','w',encoding='utf-8') as file:
  11.         file.write(requestMercadoLivre.text)
  12.  
  13.     with open('localizado.html','r',encoding='utf-8') as f:
  14.         soup = BeautifulSoup(f.read(),'html5lib')  
  15.         #foto = soup.find('img',class_='lazy-load')['src']
  16.         #produtos = soup.find(class_='results stack')
  17.         #wget.download(foto)
  18.        
  19.         '''
  20.        nomes = soup.find_all(class_='main-title')
  21.        for produtos in nomes:
  22.            print(produtos)
  23.        '''
  24.         itens =  soup.find(class_='results-item highlighted article stack product')
  25.         if(itens == None):
  26.             print('deu merda')
  27.         else:
  28.             with open(r'C:\Users\vinissh\OneDrive - Processor\Área de Trabalho\itens.html','wb',encoding='utf-8') as file:
  29.                 file.write(itens)
  30. except ValueError:
  31.     pass
Advertisement
Add Comment
Please, Sign In to add comment