This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
AntiCopyright.py
154 lines (118 loc) · 4.72 KB
/
AntiCopyright.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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import datetime
import time
import urllib.parse
import warnings
import os.path
from sys import platform
from bs4 import BeautifulSoup
from art import *
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
CLASSNAME = "yuRUbf"
WINPATH = "C:\\AntiCopyright"
LINUXPATH = "//dev/AntiCopyright"
# Logs Results to a file
def LogResults(start_time : int, uniqueURLs : list, links : list, query : str, sitetext : list, pages):
# Creating the file
currentTime = round(time.time() * 1000)
if platform == "win32":
filename = os.path.join(WINPATH, f"AntiCopyright_GSReport_{currentTime}")
if not os.path.isdir(WINPATH):
os.mkdir(WINPATH)
if platform == "linux":
filename = os.path.join(LINUXPATH, f"AntiCopyright_GSReport_{currentTime}")
if not os.path.isdir(WINPATH):
os.mkdir(WINPATH)
file = open(f"{filename}.txt", 'w', encoding="utf-8")
file.write(f"""(c) Copyright {datetime.date.today().year} Agesoft. All Rights Reserved
AntiCopyright Google Scrapping report from {datetime.date.today()}\n
Details:
Query: "{query}"
Indexes Found: {len(links)}
Pages Scanned: {pages}
URLs: {len(uniqueURLs)}\n\n""")
for i in range(0, len(links)):
file.write(f"Text: {sitetext[int(i)]}\nLink: {links[int(i)]}\n\n")
file.write("URLs:\n")
for i in range(0, len(links)):
parsed = urllib.parse.urlparse(links[int(i)])
phn = parsed.hostname
if phn not in uniqueURLs:
uniqueURLs.append(phn)
for i in range(0, len(uniqueURLs)):
file.write(f"{uniqueURLs[int(i)]}\n")
print(f"[Success] File can be found at: {file.name}")
file.close()
print(f"Successfully Scrapped! [{round(time.time() - start_time)}s]")
def ScrapGoogle(query : str, pages : int):
start_time = time.time() # Start Timestamp
links = [] # URLs
sitetext = [] # Site Text
uniqueURLs = [] # Unique URLs
# Scrapping each Google Search site
for page in range(1, pages):
print(f"Search Page: {page}")
url = "http://www.google.com/search?hl=en&q=" + query + "&start=" + str((page - 1) * 10)
driver.get(url)
soup = BeautifulSoup(driver.page_source, 'lxml')
elements = soup.find_all('div', class_=CLASSNAME)
for h in elements:
link = h.a.get('href')
links.append(link)
sitetext.append(h.h3.text)
for i in range(0, len(links)):
print(f"Text: {sitetext[int(i)]}\nLink: {links[int(i)]}\n\n")
# Appends every unique URL in the list
for i in range(0, len(links)):
parsed = urllib.parse.urlparse(links[int(i)])
phn = parsed.hostname
if phn not in uniqueURLs:
uniqueURLs.append(phn)
LogResults(start_time, uniqueURLs, links, query, sitetext, pages)
tprint("AntiCopyright")
print("------------------------------[ By Agesoft ]--------------------------------")
print("Setting up ChromeDriver")
# Shut Up!
warnings.filterwarnings("ignore", category=DeprecationWarning)
# Setting up ChromeDriver
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument("--headless")
driver = webdriver.Chrome(ChromeDriverManager().install(), chrome_options=chrome_options)
print("[1] Scrap Google Search")
print("[2] Automatically Scrap Google Search\n")
choice = int(input("Enter Option: "))
if choice == 1:
query = str(input("Enter search query: "))
pages = int(input("How many pages should be scanned: "))
ScrapGoogle(query, pages)
if choice == 2:
links = [] # URLs
sitetext = [] # Site Text
uniqueURLs = [] # Unique URLs
pages = 1000
scannedpages = 1
try:
query = str(input("Enter search query: "))
# Scrapping each Google Search site
print("Starting scrapping:\n\n")
while True:
for page in range(1, pages):
print(f"Search Page: {page}")
url = "http://www.google.com/search?hl=en&q=" + query + "&start=" + str((page - 1) * 10)
driver.get(url)
soup = BeautifulSoup(driver.page_source, 'lxml')
elements = soup.find_all('div', class_=CLASSNAME)
for h in elements:
link = h.a.get('href')
links.append(link)
sitetext.append(h.h3.text)
for i in range(0, len(links)):
print(f"Text: {sitetext[int(i)]}\nLink: {links[int(i)]}\n\n")
time.sleep(5)
scannedpages = scannedpages + 1
except KeyboardInterrupt:
print("Scrapping stopped")
LogResults(0.0, uniqueURLs, links, query, sitetext, scannedpages)
if choice > 2:
print("Error: Invalid Choice")
exit(1)