-
Notifications
You must be signed in to change notification settings - Fork 0
/
exercise1.py
45 lines (33 loc) · 1.34 KB
/
exercise1.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
#!/usr/bin/python3
# -*- encoding: utf-8 -*-
import sys
import argparse
from bs4 import BeautifulSoup
from urllib.request import Request, urlopen
class Main():
def run(self, args):
'''Definition of the main method of the program'''
args = self.arguments()
if len(sys.argv) < 2:
print("[-] Usage python3 exercise1.py -d <url_webpage>\n[-] Example: python3 exercise1.py -d thehackerway.com")
sys.exit()
list_links = []
list_forms = []
req = Request("https://" + args.domain)
html_page = urlopen(req)
soup = BeautifulSoup(html_page, 'lxml')
links = soup.find_all("a")
forms = soup.find_all("form")
for link in links:
list_links.append(link.get('href'))
for form in forms:
list_forms.append(form)
print("List of webpage links: {}\n\nList of webpage forms: {}".format(list_links, list_forms))
def arguments(self):
'''Indicates the command line parameters available for executing the script list of website links'''
parser = argparse.ArgumentParser(description="Exercise 1 - Module 7")
parser.add_argument("-d", "--domain", required=False, help="Domain of webpage")
args = parser.parse_args()
return args
foo = Main()
foo.run(sys.argv)