python网络爬虫-爬取《斗破苍穹》全文小说 源码

一家懂得用细节留住客户的3年潮牌老店我必须支持!➕:luyao1931

python网络爬虫-爬取《斗破苍穹》全文小说 源码_第1张图片

python网络爬虫-爬取《斗破苍穹》全文小说 源码

import sys
reload(sys)
sys.setdefaultencoding("utf-8")
import requests
import re
import time

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

f = open('C:/Users/hammer/Desktop/doupo.txt','a+')

def get_info(url):
    res = requests.get(url,headers=headers)
    if res.status_code == 200:
        contents = re.findall('

(.*?)

'
,res.content.decode('utf-8'),re.S) for content in contents: f.write(content+'\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) time.sleep(1) f.close()

你可能感兴趣的:(python网络爬虫)