forked from alder/woodpycker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
woodpycker.py
71 lines (56 loc) · 2.17 KB
/
woodpycker.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
#!/usr/bin/env python
#-*- coding: utf-8 -*-
import sys,os
from urlparse import urlparse
from selenium import webdriver
from browsermobproxy import Server
from colorama import init, Fore, Style
def show_status_codes(har,allowed_domain):
for entry in har['log']['entries']:
domain = urlparse(entry['request']['url'])
domain = domain.netloc
if domain.find(allowed_domain) != -1:
if entry['response']['status'] >= 200 and entry['response']['status'] < 300:
status = Fore.GREEN + str(entry['response']['status']) + " - " + entry['response']['statusText'] + Fore.RESET
if entry['response']['status'] >= 400 and entry['response']['status'] < 500:
status = Fore.YELLOW + str(entry['response']['status']) + " - " + entry['response']['statusText'] + Fore.RESET
if entry['response']['status'] >= 500 and entry['response']['status'] < 600:
status = Fore.RED + str(entry['response']['status']) + " - " + entry['response']['statusText'] + Fore.RESET
print "-- %s [%s]" % (entry['request']['url'],status)
def main():
init()
if len(sys.argv) >= 2:
start_url = sys.argv[1]
else:
print "You must specify page URL!"
sys.exit()
allowed_domain = urlparse(start_url).netloc
browsermobproxy_path = "/usr/local/opt/browsermobproxy/bin/browsermob-proxy"
options = {
'port': 9090,
}
server = Server(browsermobproxy_path,options)
server.start()
proxy = server.create_proxy()
profile = webdriver.FirefoxProfile()
profile.set_proxy(proxy.selenium_proxy())
driver = webdriver.Firefox(firefox_profile=profile)
driver.get(start_url)
links = driver.find_elements_by_tag_name('a')
lenl = len(links)
for i in range(0,lenl):
if links[i].is_displayed():
url = links[i].get_attribute('href')
text = links[i].get_attribute('text')
if url.find(allowed_domain) != -1:
proxy.new_har('demo')
links[i].click()
print "%s Clicked on the link '%s' with HREF '%s'" % (Fore.BLUE+"*"+Fore.RESET,Style.BRIGHT+text+Style.RESET_ALL,Style.BRIGHT+url+Style.RESET_ALL)
show_status_codes(proxy.har,allowed_domain)
driver.back()
driver.refresh()
links = driver.find_elements_by_tag_name('a')
driver.quit()
server.stop()
if __name__ == '__main__':
main()