-
Notifications
You must be signed in to change notification settings - Fork 2
/
Swoo_Hack.py
executable file
·131 lines (103 loc) · 3.45 KB
/
Swoo_Hack.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
import pytesseract
import pyscreenshot as ImageGrab
from bs4 import BeautifulSoup
from selenium import webdriver
import time
import threading
def replacements():
global toSearch
normal_replaces = {'The ', 'Who ', 'What ', 'Which ', 'Whom ', 'of ', 'these ', 'which'}
plus_replaces = {' following ', ' is ', ' these ', ' an ', ' a ', ' the ', ' which ', ' not ', ' what ', ' who '}
for rep in normal_replaces:
toSearch = toSearch.replace(rep, '')
toSearch = toSearch.lower()
for rep in plus_replaces:
toSearch = toSearch.replace(rep, '+')
toSearch = toSearch.replace('?', '').replace('\'', '').replace('\n', '+').replace(' ', '+').replace('++', '+').replace(',', '')
print("\n" + toSearch + "\n")
def printer(a, results):
print(a, end = "")
counter_imp = [0] * 3
counter = [0] * 3
for result in results:
result = result.getText().lower()
for i in range(0, 3):
counter_imp[i] = counter_imp[i] + result.count(options[i])
words = options[i].replace('the ', '').strip().split(' ')
for word in words:
counter[i] = counter[i] + result.count(word.strip())
start = "\033[1m"
end = "\033[0;0m"
print(start)
for i in range(0, 3):
print(str(counter_imp[i]), end=" ")
print(end)
for i in range(0, 3):
print(str(counter[i]), end=" ")
print("\n")
def bing(url, class_div, driver):
global count
try:
driver.get(url)
html = driver.page_source
soup = BeautifulSoup(html, "html.parser")
except Exception as e:
print("ERROR")
if (time.time() - start_time) >= 10 or count > 10:
print("Timeout " + str(count))
count = count + 1
return
else:
count = count + 1
bing(url, class_div, driver)
bing_results = soup.findAll("div", {"class": class_div})
printer("Bing", bing_results)
def google(url, class_div, driver):
global count
try:
driver.get(url)
html = driver.page_source
soup = BeautifulSoup(html, "html.parser")
except Exception as e:
print("ERROR")
if (time.time() - start_time) >= 10 or count > 10:
print("Timeout " + str(count))
count = count + 1
return
else:
count = count + 1
google(url, class_div, driver)
google_results = soup.findAll("div", {"class": class_div})
printer("Google", google_results)
start_time = time.time()
SWOO = (120, 658, 550, 840)
im1 = ImageGrab.grab(SWOO)
options = pytesseract.image_to_string(im1, lang='eng')
options = options.replace(options[:3], '').strip()
options = options.split("\n\n")
toSearch = options[0]
options.pop(0)
options[0] = options[0].lower()
options[1] = options[1].lower()
options[2] = options[2].lower()
replacements()
URL1 = "http://www.bing.com/search?q=" + toSearch
CLASS1 = "b_caption"
URL2 = "http://www.google.com/search?q=" + toSearch
CLASS2 = "rc"
chromeOptions = webdriver.ChromeOptions()
chromeOptions.add_argument("headless")
driver = webdriver.Chrome(chrome_options=chromeOptions)
#thread1 = threading.Thread(target=bing(URL1, CLASS1, driver), args=())
#thread2 = threading.Thread(target=google(URL2, CLASS2, driver), args=())
bing(URL1, CLASS1, driver)
google(URL2, CLASS2, driver)
driver.close()
driver.quit()
"""
thread1.start()
thread2.start()
thread1.join()
thread2.join()
"""
print("--- %s seconds ---" % (time.time() - start_time))