Python 爬虫小练习--爬取笔趣阁小说

import requests
import re
import sys

def get_content(url):
    content = requests.get(url).text
    pattern = re.compile('(.*?)
',re.S) results = re.findall(pattern,content) oldzw = results[0] newzw = re.sub('
','\n\n',oldzw) newzw = re.sub(' ','',newzw) return newzw dir = 'https://www.biqukan.com/1_1094/' content = requests.get(dir).text pattern = re.compile('
(.*?)
',re.S) results = re.findall(pattern,content) for result in results: tit = re.sub('\s','',result[1]) url = "https://www.biqukan.com" + result[0] with open('E:\\一念永恒\\' + tit + '.txt','a') as f: f.write(result[1] + '\n===========================\n\n') f.write(get_content(url)) f.close()

 

你可能感兴趣的:(Python 爬虫小练习--爬取笔趣阁小说)