-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathmain_cookies.py
64 lines (53 loc) · 2.28 KB
/
main_cookies.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
from src.article_content_spider import ArticleContentSpider
from src.article_id_spider import ArticleIdSpider
"""
Auther : SnailMann
temporary cookies version
"""
HOME_URL = 'https://blog.csdn.net/'
PAGE_URL = '/article/list/'
MARKDOWN_URL = 'https://mp.csdn.net/mdeditor/getArticle?id='
"""User Settings"""
GLO_CONFIG = {
'download_path': r"D:\csdn-blog-backup", # Default path
'download_img': False, # Default not to download pictures
'sleep_time': 1,
'name': 'yourname', # https://blog.csdn.net/yourname <- yourname
'cookies': 'yourcookies'
}
def _main():
"""
Main Logic
:return:
"""
# Initialization
article_id_spider = ArticleIdSpider()
article_content_spider = ArticleContentSpider()
print("==================================================begin====================================================")
print("Backup Path : %s" % GLO_CONFIG['download_path'])
print("Download Picture Or Not ? %s" % GLO_CONFIG['download_img'])
print("Crawl article interval : %s seconds" % GLO_CONFIG['sleep_time'])
print("===========================================================================================================")
# backup article
global HOME_URL
article_ids = article_id_spider.getArticleId(HOME_URL + GLO_CONFIG['name'],
HOME_URL + GLO_CONFIG['name'] + PAGE_URL)
article_content_spider.getArticle(GLO_CONFIG['sleep_time'],
GLO_CONFIG['download_path'], GLO_CONFIG['download_img'],
MARKDOWN_URL, article_ids, convert_cookies_to_dict(GLO_CONFIG['cookies']))
# end
print('')
print("===========================================================================================================")
print("User %s have a total of %s articles, It's all finished. Please check it." % (
GLO_CONFIG['name'], str(len(article_ids))))
input("====================================================end====================================================")
def convert_cookies_to_dict(cookies):
'''
convert cookies to dict
:param cookies:
:return:
'''
cookies = dict([l.split("=", 1) for l in cookies.split("; ")])
return cookies
if __name__ == '__main__':
_main()