All Links from given Webpage
This commit is contained in:
17
get_links.py
Normal file
17
get_links.py
Normal file
@@ -0,0 +1,17 @@
|
||||
import requests as rq
|
||||
from bs4 import BeautifulSoup
|
||||
|
||||
url = input("Enter Link: ")
|
||||
if ("https" or "http") in url:
|
||||
data = rq.get(url)
|
||||
else:
|
||||
data = rq.get("https://" + url)
|
||||
soup = BeautifulSoup(data.text, "html.parser")
|
||||
links = []
|
||||
for link in soup.find_all("a"):
|
||||
links.append(link.get("href"))
|
||||
|
||||
# Writing the output to a file (myLinks.txt) instead of to stdout
|
||||
# You can change 'a' to 'w' to overwrite the file each time
|
||||
with open("myLinks.txt", 'a') as saved:
|
||||
print(links[:10], file=saved)
|
||||
Reference in New Issue
Block a user