-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathheaders.py
35 lines (27 loc) · 951 Bytes
/
headers.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
import googlesearch
from googlesearch import search
from firewall import active
MAIN_DIR = "./docs/"
def user_agent():
# Information about user agent
print(">> User agant :")
print(googlesearch.get_random_user_agent())
def safe_search(query, bound, output):
# Opening a connection and getting a list of search
try:
response = list(search(query, num=10, stop=10, pause=bound, safe="on"))
except Exception as e:
print(f"> Error in :: {e}") # connection handeling
response = []
with open(f'{MAIN_DIR}{output}.txt', "w") as file: # save them into a file
for result in response:
if active(result):
file.write(result + "\n")
def normal_search(query, bound, output):
# To search in an normal way
with open(f'{MAIN_DIR}{output}.txt', 'w') as file:
try:
for j in search(query, tld="com", num=10, stop=10, pause=bound):
file.write(j + "\n")
except Exception as e:
print(f"> Error in :: {e}")