forked from Manish57-droid/python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinks.py
More file actions
33 lines (24 loc) · 692 Bytes
/
links.py
File metadata and controls
33 lines (24 loc) · 692 Bytes
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
import requests
import re
import argparse
parser = argparse.ArgumentParser(
description="Get list of links from a website"
)
parser.add_argument("url", nargs="?", help="URL", default=None)
arguments = parser.parse_args()
use_arguments = True if arguments.url is not None else False
# Check whether url will be obtained from command line argument
# or from user input
if use_arguments:
url = arguments.url
else:
while True:
url = input("Enter the URL: ")
if url == "":
print("Invalid URL")
continue
break
html = requests.get(url).text
links = re.findall('"(https?://.*?)"', html)
for link in links:
print(link)