-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwebDriver.py
32 lines (23 loc) · 908 Bytes
/
webDriver.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
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.options import Options
from bs4 import BeautifulSoup
from time import time, sleep as sl
def startBrowser():
options = Options()
options.headless = True; options.add_argument("--log-level=3")
options.page_load_strategy = 'eager'
browser = webdriver.Chrome(ChromeDriverManager().install(), options=options)
return browser
def getSoup(browser, url):
browser.get(url)
print('\nCarregando a página: ' + url)
t0 = time()
t1 = 0
while len(browser.find_elements_by_class_name("odd")) < 1 and len(browser.find_elements_by_class_name("run")) < 1 and t1-t0 <= 4:
sl(0.5)
t1 = time()
if t1-t0 >= 4: print('timeout'); return None
webSite = browser.page_source
soup = BeautifulSoup(webSite, 'html.parser')
return soup