求助:小说章节标题已获取,获取内容时出现了问题

avatar
作者
筋斗云
阅读量:0
import json
import requests
import asyncio
import aiohttp\
headers = {
    'Accept': '*/*',
    'Accept-Language': 'zh-CN,zh;q=0.9',
    'Cache-Control': 'no-cache',
    'Connection': 'keep-alive',
    'Pragma': 'no-cache',
    'Referer': 'https://boxnovel.baidu.com/boxnovel/detail?gid=4356714359&data=%7B%22fromaction%22%3A%22dushu%22,%22fromaction_original%22%3A%22dushu%22%7D',
    'Sec-Fetch-Dest': 'empty',
    'Sec-Fetch-Mode': 'cors',
    'Sec-Fetch-Site': 'same-origin',
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36',
    'sec-ch-ua': '"Not/A)Brand";v="8", "Chromium";v="126", "Google Chrome";v="126"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"Windows"',
}
params = {
    'bookid': '4356714359',
    'pageNum': '1',
    'order': 'asc',
    'site': '',
}
def getcha(url):
    response = requests.get(url=url, params=params,headers=headers,)
    context = json.loads(response.text)
    for chapcount in context['data']['chapter']["chapterInfo"][1:]:
        chapter_title =chapcount["chapter_title"]
        chapter_id = chapcount["chapter_id"]
        print(chapter_title,chapter_id)

if __name__ == '__main__':
    url = 'https://boxnovel.baidu.com/boxnovel/wiseapi/chapterList'
    getcha(url)

以下内容正在研究中,有高手指点吗?

    # res=requests.get('https://boxnovel.baidu.com/boxnovel/content?gid=4356714359&data={"fromaction":"dushu","fromaction_original":"dushu"}&cid=1571713073')
    # print(res.text)
    res=requests.get('https://novel-content-new.cdn.bcebos.com/6750456234407505783?md5hash=cd8773e68d78c3b3b2ac55b52559859b&timestamp=1722511408')
    res.encoding='utf-8'
    print(res.text)
    # https://boxnovel.baidu.com/boxnovel/wiseapi/getBookInfo?bookid=4356714359
    # https: // novel - content - new.cdn.bcebos.com / 6750456234407505783?md5hash = d6740ed9a68c2b4713ce0c6638182884 & timestamp = 1722510567

广告一刻

为您即时展示最新活动产品广告消息,让您随时掌握产品活动新动态!