-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
RouterScrape.py
40 lines (27 loc) · 1.17 KB
/
RouterScrape.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
import requests
from bs4 import BeautifulSoup
ROUTER_URL = "http://www.routerpasswords.com/"
def get_router_names():
"""Scrape all vendor names from routerpasswords.com"""
name_list = []
soup = requests.get(url=ROUTER_URL)
soup = BeautifulSoup(soup.text, "lxml")
for name in soup.findAll("option"):
name_list.append(name.text)
return name_list
def download_router_info(name, path):
"""Searches for information on a selected vendor and saves response in a text file"""
passwords_list = []
name = name.upper()
#params = {"findpass": 1, "router": f"{name}", "findpassword": "Find Password"}
soup = requests.post(url=ROUTER_URL+"/router-password/"+name)
soup = BeautifulSoup(soup.text, "lxml")
for tags in soup.findAll("td"):
passwords_list.append(tags.text.replace("\n", "").replace("\r", ""))
pass_write = open(path, "a")
for n, info in enumerate(passwords_list):
if len(info.split()) > 6: # Removes random extra data I recieved from HP request
continue
pass_write.write("%-*s".strip("\n") % (108, info))
if (n + 1) % 5 == 0: pass_write.write("\n")
pass_write.close()