Python3 html获取
来源:互联网 发布:淘宝设计属于什么行业 编辑:程序博客网 时间:2024/06/06 01:18
import urllib.request #导入urllib库的request模块
#指定要抓取的网页url,必须以http开头的
url='http://blog.csdn.net/u014453898/article/details/54848707'
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'}
#调用 urlopen()从服务器获取网页响应(respone),其返回的响应是一个实例
respone=urllib.request.urlopen(url)
#调用返回响应示例中的read()函数,即可以读取html,但需要进行解码,
#具体解码写什么,要在你要爬取的网址右键,查看源代码;如‘utf-8’
html=respone.read().decode('utf-8')
'''# print(respone.info())——info()获取编码方式 #'''
urllib.request.urlretrieve(url,'./html_doc.txt')
#指定要抓取的网页url,必须以http开头的
url='http://blog.csdn.net/u014453898/article/details/54848707'
headers={'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'}
#调用 urlopen()从服务器获取网页响应(respone),其返回的响应是一个实例
respone=urllib.request.urlopen(url)
#调用返回响应示例中的read()函数,即可以读取html,但需要进行解码,
#具体解码写什么,要在你要爬取的网址右键,查看源代码;如‘utf-8’
html=respone.read().decode('utf-8')
'''# print(respone.info())——info()获取编码方式 #'''
urllib.request.urlretrieve(url,'./html_doc.txt')
阅读全文
1 0
- Python3 html获取
- Python3处理HTML获取所需内容
- python3爬虫获取html内容及各属性值
- Python3 HTML 解析器
- python3 解析html
- Python3.5爬虫入门示例-获取百度首页及相关的html页面
- python3获取天气预报
- python3获取天气预报
- python3获取天气信息
- Python3获取网页内容
- Python3.5.1获取笑话
- python3 获取int最大值
- Python3:抓取网页HTML代码
- python3 爬虫 HTML 指定内容
- Python3怎样生成Html测试报告
- python3.X爬虫-图片获取
- python3获取天气预报(转)
- python3.4 获取302请求
- [HDU2853]Assignment(KM双元限制)
- Android 高亮引导 亲测可行
- java-mail的程序在服务器上运行出现error的解决方法
- Android5.0 WebView中Http和Https混合问题
- 树莓派开机-图形界面-自启动全屏Chrome浏览器
- Python3 html获取
- oracle实现 无则insert插入,有则update更新,一条语句直接进行insert/update操作
- PHP中的use关键字及文件的加载说明
- 记一次C++线程函数使用标志位的经历
- Mysql导入大容量SQL文件数据问题
- Python自然语言处理工具小结
- leetcode 179. Largest Number
- Hibernate的学习之路二(入门)
- vtk学习之路—第一章