目标:成功爬取一个小说网站的某个小说所有内容:
工具:Python3.5,pycharm
历时:12小时(很多时间都在纠结)
结果:当然是成功了
# -*- coding: utf-8 -*- import requests import re import string #下载一个网页 url = 'http://www.jingcaiyuedu.com/book/15401/list.html' #模拟浏览器发送http请求,通过requests发送url get请求,服务器response # 返回响应、 数据等 response = requests.get(url) #规定网页编码方式 response.encoding = 'utf-8' #目标小说主页源代码 html = response.text #小说名字 # title = re.findall(r'<title>(.*?)</title>', html) #新建一个文件,保存小说内容