-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.py
More file actions
38 lines (29 loc) · 1.4 KB
/
app.py
File metadata and controls
38 lines (29 loc) · 1.4 KB
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
from time import sleep
from selenium import webdriver
from bs4 import BeautifulSoup
from planilha import criaPlan
nv = webdriver.Chrome() #declarando o navegador
nv.get("https://amazon.com.br") #navegando até a página inicial da amazon
barPesquisa = nv.find_element('xpath','//*[@id="twotabsearchtextbox"]') #reconhecendo a barra de pesquisa
barPesquisa.click() #clicando na barra de pesquisa
barPesquisa.send_keys("iPhone") #inserindo o produto que quero pesquisar
confirmar=nv.find_element('xpath','//*[@id="nav-search-submit-button"]') #reconhecendo o botão para confirmar a pesquisa
confirmar.click()
sleep(5)
pagConteud = nv.page_source
bs = BeautifulSoup(pagConteud,"html.parser")
tagsPai = bs.find_all('div', attrs={'data-component-type':'s-search-result'})
produtos = []
for i in tagsPai:
precoInt = i.find('span',attrs={'class':'a-offscreen'})
#precoInt = i.find('span',attrs={'class':'a-price-whole'}) /*caminho mais longo de obter o preço*/
#precoFrac= i.find('span',attrs={'class':'a-price-fraction'}) /*caminho mais longo*/
if str(type(precoInt)) != "<class 'NoneType'>":
#preco = str(precoInt.text) + str(precoFrac.text) /*caminho mais longo*/
preco = str(precoInt.text)
else:preco = 'Indeterminado'
h2 = i.find('h2')
nome = h2.find('span')
nome = str(nome.text)
produtos.append({'nome':nome,'valor':preco})
criaPlan('iPhone_Amazon', produtos)