Skip to content

Commit e003227

Browse files
authored
Merge pull request Python-World#193 from mikeysan/patch-1
Update get_links.py
2 parents 7b998cf + 1287918 commit e003227

1 file changed

Lines changed: 9 additions & 3 deletions

File tree

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,17 @@
11
import requests as rq
22
from bs4 import BeautifulSoup
33

4-
url = input("Enter Link")
5-
data = rq.get(url)
4+
url = input("Enter Link: ")
5+
if ("https" or "http") in url:
6+
data = rq.get(url)
7+
else:
8+
data = rq.get("https://" + url)
69
soup = BeautifulSoup(data.text, "html.parser")
710
links = []
811
for link in soup.find_all("a"):
912
links.append(link.get("href"))
1013

11-
print(links[:10])
14+
# Writing the output to a file (myLinks.txt) instead of to stdout
15+
# You can change 'a' to 'w' to overwrite the file each time
16+
with open("myLinks.txt", 'a') as saved:
17+
print(links[:10], file=saved)

0 commit comments

Comments
 (0)