-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkParser.py
More file actions
43 lines (39 loc) · 1.04 KB
/
linkParser.py
File metadata and controls
43 lines (39 loc) · 1.04 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
#coding=UTF-8
from anonBrowser import *
from BeautifulSoup import BeautifulSoup
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',help='specify target url')
(options,args) = parser.parse_args()
url = options.tgtURL
if url==None:
print parser.usage
exit(0)
else:
printLinks(url)
if __name__ == '__main__':
main()