diff --git a/README.md b/README.md index daa5f3d..ebb2a7d 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,14 @@ -# All_Links_from_given_Webpage +# All Links from given Webpage +Этот скрипт извлекает все ссылки с заданной веб-страницы и сохраняет их в виде текстового файла. + +> BeautifulSoup4 +> requests + +to install: +``` +pip install -r req.pip +python get_links.py +``` + +Затем вас спросят, какую веб-страницу вы хотите проанализировать. После этого извлеченные ссылки будут сохранены в виде массива в myLinks.txt. \ No newline at end of file diff --git a/get_links.py b/get_links.py new file mode 100644 index 0000000..968ed18 --- /dev/null +++ b/get_links.py @@ -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) \ No newline at end of file diff --git a/myLinks.txt b/myLinks.txt new file mode 100644 index 0000000..ac0121e --- /dev/null +++ b/myLinks.txt @@ -0,0 +1 @@ +['https://trk.mail.ru/c/i02y74?mt_sub1=home', 'https://trk.mail.ru/c/cptmm9?mt_sub1=home', 'https://trk.mail.ru/c/psc3a5?mt_sub1=home', 'https://trk.mail.ru/c/jr23b4?mt_sub1=home', 'https://trk.mail.ru/c/gqhkg6?mt_sub1=mail.ru&mt_campaign=newpromomail&mt_sub2=navinew', 'https://trk.mail.ru/c/fvhzw7?mt_sub1=home', 'https://trk.mail.ru/c/t6ks72?mt_sub1=home', 'https://trk.mail.ru/c/bwzm48?mt_sub1=home', 'https://trk.mail.ru/c/yr65t1?mt_sub1=home', 'https://trk.mail.ru/c/bgt8c3?mt_sub1=home'] diff --git a/req.pip b/req.pip new file mode 100644 index 0000000..ce98cb1 --- /dev/null +++ b/req.pip @@ -0,0 +1,2 @@ +beautifulsoup4==4.12.3 +requests==2.31.0 \ No newline at end of file