猫史档案馆


【Python作品分享】下载《编程猫传》小说程序【作业帖】

用户:爱编程的小程序员爱编程的小程序员查看:0 回复:2 评论:0 创建时间:2022-10-21T21:15:58


【作品展示】

center_image

 

【作品介绍】

用于下载《编程猫传》小说文本内容(txt)

 

【作品源代码】

import requests
import json
from bs4 import BeautifulSoup

section_list_url = "https://backend-test.codemao.cn/teaching/api/fanfic/19786"
response = requests.get(section_list_url)
data = json.loads(response.text)
sectionList = data['data']['sectionList']
print(sectionList)
for section in sectionList:
    section_id = section['id']
    section_url = "https://backend-test.codemao.cn/teaching/api/fanfic/section/" + str(section_id)
    response = requests.get(section_url)
    data = json.loads(response.text)

    text = data['data']['section']['content']
    soup = BeautifulSoup(text, "lxml")
    text = soup.get_text()
    title = section["title"]
    separator = f"\n\n{title}\n=========================\n\n"


    with open(f"编程猫传.txt", "a", encoding="utf-8") as f:
        f.write(separator + text)

 

【提示】

部分含有Python第三方库相关内容的作品,在海龟编辑器网页端无法运行哦!如遇到这种情况,可以打开下面的链接,下载海龟编辑器客户端:

https://python.codemao.cn


回复

上一页1 页 / 共 1下一页
星河非昨夜星河非昨夜

。。。

点赞0


评论


希望能成为大神,加油希望能成为大神,加油

文件去哪啦!!!!!!!!!

点赞0


评论