欢迎光临散文网 会员登陆 & 注册

获取免费小说,免费小说随时看

2020-05-28 22:35 作者:每日一遍__以防抑郁  | 我要投稿

很多时候我们追小说时候,总会有很多的广告,让我们看小说的心情大打折扣,下面让我们来获取免费小说,获取到本地随时可以看吧。

import requests,re,parsel

from fake_useragent import UserAgent


ua = UserAgent()

header = {"User-Agent":ua.random}


Url = "https://www.167k.com/book/20761"


session = requests.session()

session.headers = header


def local(url,title,num):

    try:

        res = session.get(url)

        if res.status_code == 200:

            url = "https://www.167k.com/phone/book/get_bookcontent?book_id={}&chapter_id={}".format(num[2], num[3])

            res = session.get(url)

            print(res.text)

    except Exception as e:

        print("详细页面请求出错:",e)


def main():

    try:

        res = requests.get(Url,headers=header)

        # 获取总标题 和一个图片

        if res.status_code == 200:

            html = parsel.Selector(res.text)

            image = html.xpath('//div[@class="de_navtu"]/div[1]/img/@src').extract_first()

            # 留意一下这里标题是否有作者名字

            title_all = html.xpath('//div[@class="de_navtu"]/div[2]/div[1]/text()').extract_first()

            name = html.xpath('//div[@class="de_navtu"]/div[2]/div[1]/span/text()').extract_first()

            title_all = title_all.replace("\n","").replace("\t","")

            mold = html.xpath('//div[@class="de_navtu"]/div[2]/div[2]/div/text()').extract()

            # print(mold)

            # print("图片链接:",image)

            # print("总标题:",title_all)

            # print("作者:",name,len(name))

            # print(title_all,len(title_all))

            titles = html.xpath('//div[@class="bo_zj"]/ul/li/a/@title').extract()

            urls = html.xpath('//div[@class="bo_zj"]/ul/li/a/@href').extract()

            for title,url in zip(titles,urls):

                #  https://www.167k.com/book/20761/126590035     构造这个URL

                #  https://www.167k.com/phone/book/get_bookcontent?book_id=20761&chapter_id=126590035

                #  https://www.167k.com/phone/book/get_bookcontent?book_id=20761&chapter_id=126590117

                if url == '/book/20761/126590007':

                    num = url.split('/')

                    url = "https://www.167k.com{}".format(url)

                    local(url,title,num)

                    print(url)

                # url = "https://www.167k.com{}".format(url)

                # print(title,url)

        else:

            print("不是200")



    except Exception as e:

        print("请求主页面出错:",e)



if __name__ == '__main__':

    main()


获取免费小说,免费小说随时看的评论 (共 条)

分享到微博请遵守国家法律