Python基础 urllib
来源:互联网 发布:公文的阅知范围体现在 编辑:程序博客网 时间:2024/05/18 01:14
Get 获取网页内容
urllib的request模块可以非常方便地抓取URL内容,也就是发送一个GET请求到指定的页面,然后返回HTTP的响应
示例
#!/usr/bin/env python3# -*- coding: utf-8 -*-# Python基础 urllibfrom urllib import request# urllib提供了一系列用于操作URL的功能with request.urlopen('https://www.baidu.com/') as f: data = f.read() print("status", f.status) print("reason", f.reason) for k, v in f.getheaders(): print("%s:%s"%(k, v)) print("data", data.decode("utf-8"))
运行结果
D:\PythonProject>python main.pystatus 200reason OKAccept-Ranges:bytesCache-Control:no-cacheContent-Length:227Content-Type:text/htmlDate:Wed, 20 Dec 2017 14:17:53 GMTLast-Modified:Thu, 07 Dec 2017 06:53:00 GMTP3p:CP=" OTI DSP COR IVA OUR IND COM "Pragma:no-cacheServer:BWS/1.1Set-Cookie:BD_NOT_HTTPS=1; path=/; Max-Age=300Set-Cookie:BIDUPSID=679581176346342B5F42D3A649A6B51C; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.comSet-Cookie:PSTM=1513779473; expires=Thu, 31-Dec-37 23:55:55 GMT; max-age=2147483647; path=/; domain=.baidu.comStrict-Transport-Security:max-age=0X-Ua-Compatible:IE=Edge,chrome=1Connection:closedata <html><head> <script> location.replace(location.href.replace("https://","http://")); </script></head><body> <noscript><meta http-equiv="refresh" content="0;url=http://www.baidu.com/"></noscript></body></html>
阅读全文
0 0
- Python基础 urllib
- python urllib
- python urllib
- python urllib
- python urllib
- Python urllib
- Python urllib
- python urllib
- 【python】urllib
- Python的Urllib库的使用(爬虫基础)
- Python爬虫基础细节(urllib+cookielib+BeautifulSoup)
- urllib基础练习1
- python urllib使用
- python中的urllib模块
- python urllib介绍
- python学习----urllib
- python urllib使用
- Python模块学习 --- urllib
- 安装macvim
- 单例7种写法
- Android内核开发:图解Android系统的启动过程
- SpringMVC基本注解的介绍
- java代码启动tomcat报The CATALINA_HOME enironment variable is not defined correctly.....错误
- Python基础 urllib
- 从银行转账失败到分布式事务:总结与思考
- 使用UDP协议编写一个网络程序
- IT时代的投资
- Oracle12C用户创建、授权、登录
- JSP应用
- [Nginx]Nginx简单使用(一)
- 3378 数据结构实验之查找六:顺序查找
- Linux C学习笔记 —— 字符串处理函数(string.h)