-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcrawling_function.py
More file actions
36 lines (29 loc) · 1.13 KB
/
crawling_function.py
File metadata and controls
36 lines (29 loc) · 1.13 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
from selenium import webdriver
from selenium.webdriver.common.by import By
from webdriver_manager.chrome import ChromeDriverManager
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.chrome.options import Options
def get_driver():
return webdriver.Chrome(service=Service(ChromeDriverManager().install()), options=options)
options = Options()
options.add_experimental_option("excludeSwitches", ["enable-logging"])
options.add_argument("window-size=10000,10000")
options.add_argument("lang=en-GB")
options.add_argument('--disable-gpu')
options.add_argument("no-sandbox")
# options.add_argument('--headless')
def crawl_driver(keywords=[]):
driver = get_driver()
driver.get('https://www.google.com/')
search_box = driver.find_element('name', 'q')
info_list = []
for i in range(len(keywords)):
search_box.send_keys(keywords[i])
search_box.submit()
driver.implicitly_wait(10)
span_elements = driver.find_elements(By.ID, 'rso')
for element in span_elements:
info_list.append(element.text)
driver.back()
print(info_list)
return info_list