Skip to content
This repository was archived by the owner on Nov 30, 2022. It is now read-only.

Commit b05b6a2

Browse files
authored
Merge pull request #118 from Namyalg/medium-article-downloader
Script to download Medium articles
2 parents 38b780d + e355aa3 commit b05b6a2

File tree

3 files changed

+59
-0
lines changed

3 files changed

+59
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#!/usr/bin/env python3
2+
3+
#Imports and dependencies
4+
5+
import requests
6+
from bs4 import BeautifulSoup
7+
8+
def download_article():
9+
10+
#The content is written into a text file
11+
12+
file = open("Medium_article_content.txt", "w")
13+
14+
#The URL of the article is entered here
15+
page_url = input("Enter the URL of the Medium Article ")
16+
17+
#On looking for "my user agent", can be used to retrieve the value"
18+
headers = {"User-Agent": 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:79.0) Gecko/20100101 Firefox/79.0'}
19+
20+
response = requests.get(page_url)
21+
22+
soup = BeautifulSoup(response.text,"html.parser")
23+
24+
#The content of the article is stored in the <article> tag
25+
26+
for line in soup.find('article').find('div'):
27+
28+
#All the content is essentially stored between <p> tags
29+
30+
for content in line.find_all('p'):
31+
32+
#contents are written into a file
33+
34+
file.write(content.text + '\n')
35+
36+
file.close()
37+
38+
if __name__ == "__main__":
39+
download_article()
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Medium Article Downloader #
2+
3+
![Image](medium.PNG)
4+
5+
Medium is a treasure trove of knowledge. It is a great place to read and write blogs
6+
7+
Through this script, the contents of a medium article can be downloaded and stored
8+
9+
The script is written in Python
10+
11+
The Beautiful Soup library in Python enables web scraping and enables parsing though html content, which web pages are made of. Here, the same has been used.
12+
13+
## Implementation ##
14+
15+
- The user is prompted to enter the URL of the Medium article that has to be downloaded
16+
17+
- The contents are then stored in a file named Medium$_article$_content.txt
18+
19+
20+
Loading

0 commit comments

Comments
 (0)