Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit211022b

Browse files
authored
Merge pull request#248 from gibranbadrulz/hacktoberfest-2022
add Devto Posts scraper via public API
2 parentsa9cd120 +feed0da commit211022b

File tree

1 file changed

+34
-0
lines changed

1 file changed

+34
-0
lines changed
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# USAGE:
2+
# python devto_posts_backup.py [username]
3+
4+
importrequests
5+
importos
6+
importsys
7+
8+
iflen(sys.argv)>2:
9+
print("Please only call me with one parameter")
10+
sys.exit()
11+
12+
params= {
13+
'username':sys.argv[1]
14+
}
15+
16+
result=requests.get('https://dev.to/api/articles',params=params)
17+
articles=result.json()
18+
19+
username=params['username']
20+
posts_path=os.path.join(sys.path[0],'dev.to',username,'posts')
21+
ifnotos.path.exists(posts_path):
22+
os.makedirs(posts_path)
23+
24+
forarticleinarticles:
25+
slug=article['slug']
26+
article_id=article['id']
27+
filename=f'{slug}.md'
28+
29+
article_result=requests.get(f'https://dev.to/api/articles/{article_id}')
30+
article=article_result.json()
31+
32+
f=open(os.path.join(posts_path,filename),"w+",encoding="utf-8")
33+
f.write(article['body_markdown'])
34+
f.close()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp