最近有部很火的网剧《唐砖》,虽说编剧改了很多地方,但是单单从电视剧的角度来讲,还是很不错的,也看出了剧组和演员的用心,给一个大大的赞;于是今天心血来潮,想下本原著看看,找了个笔趣看的小说网站,发现没有小说的下载地址,这就尴尬了,所以准备用python爬一下,生成一个 " 唐砖.txt " 文件传手机上。
1. 爬取博客主页信息,生成一个网页HTML文件 (预热)
import urllib.request;
page = urllib.request.urlopen('https://blog.csdn.net/wu5229485');
htmlcode = page.read();
pageFile = open('pageCode.html','wb+'); # 以写的方式打开pageCode.html
pageFile.write(htmlcode); # 写入
pageFile.close(); # 关
print('OK!');
2.安装pip工具
解决方案:https://jingyan.baidu.com/article/ff42efa9d630e5c19e220207.html
3.使用requests获取网页数据
(1)安装requests
pip install requests
中文文档:http://docs.python-requests.org/zh_CN/latest/user/quickstart.html
(2)使用requests获取网页HTML结构数据
import requests
if __name__ == '__main__':
target = "http://blog.sina.com.cn/riversfrog"
req = requests.get(target)
req.encoding =