使用python爬虫爬取小说+ 1000套ppt模板

python爬虫爬取斗破苍穹小说:

import requests

import time

import re

headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.7 Safari/537.36'}

num = 1

def get_info(url):

    res=requests.get(url,headers=headers)

    if res.status_code==200:

        contents = re.findall('<p>(.*?)</p>',res.content.decode('utf-8'),re.S)

        contents = str(contents).replace('&rdquo','')

        contents = str(contents).replace('&hellip','')

        contents = str(contents).replace('&ldquo','')

        contents = str(contents).replace(''''天才一秒记住本站网站 www.doupoxs.com 中间是<span style="color:blue">斗破 拼音+小说 首字母</span> 连起来就是斗破小说,喜欢我就记住我吧!''','')

        with open('F:/doupo.txt','a',encoding='utf-8') as f:

            f.write(contents+'\n')

    else:

        pass

if __name__=='__main__':

    urls=['http://www.doupoxs.com/doupocangqiong/{}.html'.format(str(i)) for i in range(2,1665)]

    for url in urls:

        get_info(url)

        print(num)

        num += 1

        time.sleep(1)



下载地址:

https://vk666.lanzoum.com/i1mV80sjyw5e

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容