-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbrowserController.py
More file actions
88 lines (61 loc) · 2.13 KB
/
browserController.py
File metadata and controls
88 lines (61 loc) · 2.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
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import random
import time
from selenium import webdriver
from selenium.common.exceptions import *
def searchByGoogle(driver, sQuery, timeframe):
performSearch(driver, "google", sQuery, timeframe)
def searchByDuckDuckGo(driver, sQuery, timeframe):
performSearch(driver, "ddg", sQuery, timeframe)
def performSearch(driver, sEngine, sQuery, timeframe):
if sEngine == "google":
cConsent = "L2AGLb"
sf = "q"
url = 'https://www.google.com/xhtml'
if sEngine == "ddg":
cConsent = ""
sf = "search__input--adv"
url = 'https://duckduckgo.com/'
driver.get(url)
try:
passbutton = driver.find_element_by_id(cConsent)
passbutton.click()
except NoSuchElementException:
print("id " + cConsent + " not found")
except ElementNotInteractableException:
print("id " + cConsent + " not interactable")
try:
search_field = driver.find_element_by_name(sf)
search_field.clear()
typeQuery(search_field, sQuery, timeframe)
search_field.submit()
except NoSuchElementException:
print("id " + sf + " not found")
except ElementNotInteractableException:
print("id " + sf + " not interactable")
try:
search_field = driver.find_element_by_class_name(sf)
search_field.clear()
typeQuery(search_field,sQuery, timeframe)
search_field.submit()
except NoSuchElementException:
print("id " + sf + " not found")
except ElementNotInteractableException:
print("id " + sf + " not interactable")
time.sleep(random.randint(1,500)/100)
def typeQuery (inputField, input, timeframe):
for letter in input:
print("Schreibe: " + letter)
inputField.send_keys(letter)
calculateTimeFrameMs(timeframe)
def getDriver():
driver = webdriver.Chrome("chromedriver.exe")
driver.delete_all_cookies()
time.sleep(1)
return driver
def killDriver(driver):
time.sleep(1)
driver.quit()
def calculateTimeFrameMs(timeframe):
wait = random.randint(1, timeframe) / 100
print("warte : "+ str(wait) + "s")
time.sleep(wait)