forked from xdavidhu/learning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgResults.py
130 lines (107 loc) · 3.89 KB
/
gResults.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
print(" ____ _ _ \n" +
" __ _| _ \ ___ ___ _ _| | |_ ___ \n" +
" / _` | |_) / _ \/ __| | | | | __/ __| \n" +
"| (_| | _ < __/\__ \ |_| | | |_\__ \ \n" +
" \__, |_| \_\___||___/\__,_|_|\__|___/ \n" +
" |___/ 1.0 by @xdavidhu \n")
import inspect, os
import sys
try:
from urllib.request import Request, urlopen
except:
print("\n[E] Make sure to use Python3 to run this application.\n")
exit()
try:
from bs4 import BeautifulSoup
except:
print("\n[E] BeautifulSoup is needed for this application to work.\n Please install it with 'pip3 install beautifulsoup4', and try again\n")
exit()
import re
lang_code = "en"
print("Please enter the wordlist's location:")
list = input()
tempList = list
tempList = tempList.replace('.txt', '')
tempList = tempList.replace('/', '-')
print()
tempResultFileName = "gResults" + tempList + ".txt"
try:
wordlist = open(list, 'r')
except:
print("[E] Wordlist not found. Try again with an another location.\n")
exit()
print("[I] Wordlist detected...\n")
print("[Q] Do you want to save the results in a text file? Y/n")
textQuestion = input()
textQuestion = textQuestion.lower()
if textQuestion == "y":
resultFile = open(tempResultFileName, 'w+')
print()
for word in wordlist.readlines():
word = word.split('\n')
word = word[0]
tempWord = word
word = word.lower()
tempQuery = ""
for c in word:
if c == " ":
c = "+"
tempQuery = tempQuery + c
webpage = ""
if not re.match("^[a-zA-Z0-9_+]*$", tempQuery):
print("[E] Please do not use any special characters in the wordlist.\n")
exit()
try:
url = 'https://www.google.com/search?q=' + tempQuery + "&hl=" + lang_code
req = Request(url, headers={'User-Agent': 'Mozilla/5.0'})
webpage = urlopen(req).read()
utfPage = webpage.decode(encoding='UTF-8')
soup = BeautifulSoup(utfPage, "html.parser")
except KeyboardInterrupt:
print("\nStopping...\n")
wordlist.close()
if textQuestion == "y":
location = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
if sys.platform == 'win32':
location = location + "\\" + tempResultFileName
else:
location = "'" + location + "/" + tempResultFileName + "'"
print("[I] Result saved in file: " + location + "\n")
resultFile.close()
exit()
except:
print("[E] Error while downloading the results. Do you have a working internet connection?\n")
exit()
try:
data = str(soup.find('div', {'class': 'sd'}).text)
except KeyboardInterrupt:
print("\nStopping...\n")
wordlist.close()
if textQuestion == "y":
location = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
if sys.platform == 'win32':
location = location + "\\" + tempResultFileName
else:
location = "'" + location + "/" + tempResultFileName + "'"
print("[I] Result saved in file: " + location + "\n")
resultFile.close()
exit()
except:
print("[E] Cannot load results. Is Google blocked you?\n")
exit()
data = data.replace('About ', '')
data = data.replace(' results', '')
tempPrintData = tempWord + " ==> " + data
print(tempPrintData)
if textQuestion == "y":
resultFile.write(tempPrintData + '\n')
print()
wordlist.close()
if textQuestion == "y":
location = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe())))
if sys.platform == 'win32':
location = location + "\\" + tempResultFileName
else:
location = "'" + location + "/" + tempResultFileName + "'"
print("[I] Result saved in file: " + location + "\n")
resultFile.close()