-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlink_parser.py
More file actions
44 lines (39 loc) · 1.05 KB
/
link_parser.py
File metadata and controls
44 lines (39 loc) · 1.05 KB
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
from anonBrowser import *
from BeautifulSoup import BeautifulSoup
import os
import optparse
import re
def printLinks(url):
ab = anonBrowser()
ab.anonymize()
page = ab.open(url)
html = page.read()
try:
print('[+] Printing Links From RegEx.')
link_finder = re.compile('href="(.*?)"')
links = link_finder.findall(html)
for link in links:
print(link)
except:
pass
try:
print('\n[+] Printing Links From BeautifulSoup.')
soup = BeautifulSoup(html)
links = soup.findAll(name='a')
for link in links:
if link.has_key('href'):
print(link['href'])
except:
pass
def main():
parser = optparse.OptionParser('Usage %prog ' + '-u <target url>')
parser.add_option('-u', dest='tgtURL', type='string', helf='specify target url')
(options, args) = parser.parse_args()
url = option.tgtURL
if url == None:
print(parser.usage)
exit(0)
else:
printLinks(url)
if __name__ == '__main__':
main()