Created
January 31, 2020 12:51
-
-
Save Sicalxy/08c1c83d03e48e1f1e0c904fb5462f54 to your computer and use it in GitHub Desktop.
hz computer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: UTF-8 -*- | |
import requests | |
import json | |
token = {'token': '21f7e4a349d69bbab5dc20c2647b3880'} | |
books = [ | |
['jvm', | |
'11120486', | |
'07871edf-06a8-4bd1-a8d8-aa2317a099c7_1'], | |
['python', | |
'11119310', | |
'c4f81ebc-72a1-40ec-892c-f087dc2e7252_1'], | |
['baihua', | |
'11118774', | |
'ece0bc6a-8207-4f15-b0a7-8b7567a6c09a_1'] | |
['javalogic', | |
'11118869', | |
'15c452b8-193a-415c-83d9-411b9eea6942_1'], | |
['rust', | |
'11119386', | |
'9957e5ad-2762-4b73-8fd7-8e68c7a7c205_1'], | |
['dp', | |
'11111552', | |
'6a72c44f-8d7d-4f97-8830-4e34b86f3d0c_1'], | |
['zhongtai', | |
'11118222', | |
'f731fea5-0640-47a0-8ec5-663ec65f5493_1'], | |
['flask', | |
'11119384', | |
'529e706e-ccb5-406a-a845-0c7bdbfd8bfd_1'], | |
['reids', | |
'11112416', | |
'cf9e908d-889a-4d48-ae58-5478f37a521a_1'], | |
['java', | |
'10473', | |
'9685e815-1e6f-4ba0-8780-563ac4ad9274_1'] | |
] | |
need = ['chapterid', 'content'] | |
content_url = 'http://www.hzmedia.com.cn/api/book_content_get.ashx' | |
chapter_url = 'http://www.hzmedia.com.cn/api/book_chapter_get.ashx' | |
for name, content_id, chapter_uuid in books: | |
print(name) | |
with open(name + '-content.txt', 'w', encoding='utf-8') as f: | |
payload = token | |
payload['id'] = content_id | |
text = requests.post(content_url, data=payload).text | |
data = json.loads(text)['data'] | |
f.write(json.dumps(data, ensure_ascii=False)) | |
with open(name + '.txt', 'w', encoding='utf-8') as f: | |
payload = token | |
payload['uuid'] = chapter_uuid | |
flag = True | |
next = 1 | |
while flag: | |
print(next) | |
payload['chapterid'] = next | |
text = requests.post(chapter_url, data=payload).text | |
data = json.loads(text)['data'] | |
if data['next_chapterid'] == '': | |
flag = False | |
else: | |
next = int(data['next_chapterid']) | |
data = { n : data[n] for n in need } | |
f.write(json.dumps(data, ensure_ascii=False) + '\n') | |
#input() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment