-
Notifications
You must be signed in to change notification settings - Fork 16
/
ExtractUrlsFromWebpage.py
47 lines (42 loc) · 1.15 KB
/
ExtractUrlsFromWebpage.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
import re
from datetime import date
import argparse
arguments = argparse.ArgumentParser("Extract Urls from a phishing site like PhishTank")
arguments.add_argument("-f", "--file", type=str, required=True, help="Path to file with raw copy & paste content of website")
settings = arguments.parse_args()
urlregex = r'(?i)(http|https|hxxp|hxxps)(\:\/\/[^\s]+)\s'
splitchoice1 = "http"
splitchoice2 = "hxxp"
filename = settings.file
webpageraw = ''
with open(filename, 'r') as file:
webpageraw = file.read()
splitter = splitchoice1
urlchunks = []
try:
end = webpageraw.index(splitter)
except:
splitter = splitchoice2
try:
end = webpageraw.index(splitter)
except:
end = -1
if end < 0:
urlchunks.append(webpageraw)
else:
while end >= 0:
urlchunks.append(splitter + webpageraw[:end])
newstart = end + len(splitter)
webpageraw = webpageraw[newstart:]
try:
end = webpageraw.index(splitter)
except:
end = -1
urlchunks.append(splitter + webpageraw)
for urlchunk in urlchunks:
searchurl = re.search(urlregex,urlchunk)
url = ''
if not searchurl is None:
url = searchurl[1] + searchurl[2]
if not url is None:
print("{0}".format(url).replace("...",""))