-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.py
71 lines (50 loc) · 2.07 KB
/
script.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import pandas as pd
from genericpath import exists
import os
import time
import pandas as pd
import sys
from selenium.webdriver import ActionChains
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import datetime
from webdriver_manager.chrome import ChromeDriverManager
from win10toast_click import ToastNotifier
import win32com.client as win32
options = Options()
options.page_load_strategy = 'eager'
options.headless = False
options.add_argument("--start-maximized")
driver = webdriver.Chrome(executable_path=ChromeDriverManager().install(), options=options)
pesquisa = input('O que deseja pesquisar? ')
driver.get('https://google.com.br')
driver.find_element(By.XPATH,'/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input').send_keys(pesquisa)
driver.find_element(By.XPATH,'/html/body/div[1]/div[3]/form/div[1]/div[1]/div[1]/div/div[2]/input').send_keys(Keys.ENTER)
quer_ir = int(input('Até que página você quer ir?'))
pag_atual = driver.find_element(By.XPATH,'/html/body/div[7]/div/div[10]/div/div[6]/span[1]/table/tbody/tr/td[2]').text
pag_atual = int(pag_atual)
lista_resultados = []
while pag_atual <= quer_ir:
divs = driver.find_elements(By.CLASS_NAME,'g')
i = 1
for elemento in divs:
try:
titulo = elemento.find_element(By.TAG_NAME,'h3').text
except:
...
try:
link = elemento.find_element(By.TAG_NAME,'a').get_attribute('href')
except:
...
resultados = "%s '---------' %s" % (titulo,link)
lista_resultados.append(resultados)
driver.find_element(By.XPATH,'/html/body/div[7]/div/div[10]/div/div[6]/span[1]/table/tbody/tr/td[11]/a').click()
pag_atual += 1
with open("resultados.txt", "w") as arquivo:
for resultados in lista_resultados:
arquivo.write("%s\n" % resultados)
driver.close()