Python网络爬虫(Get、Post抓取方式)
来源:互联网 发布:淘宝捡漏是怎么回事 编辑:程序博客网 时间:2024/05/19 16:49
简单的抓取网页
import urllib.request url="http://google.cn/" response=urllib.request.urlopen(url) #返回文件对象page=response.read()
直接将URL保存为本地文件
import urllib.request url="http://www.xxxx.com/1.jpg"urllib.request.urlretrieve(url,r"d:\temp\1.jpg")
POST方式
import urllib.parse import urllib.request url="http://liuxin-blog.appspot.com/messageboard/add" values={"content":"命令行发出网页请求测试"} data=urllib.parse.urlencode(values) #创建请求对象 req=urllib.request.Request(url,data) #获得服务器返回的数据 response=urllib.request.urlopen(req) #处理数据 page=response.read()
GET方式
import urllib.parse import urllib.request url="http://www.google.cn/webhp" values={"rls":"ig"} data=urllib.parse.urlencode(values) theurl=url+"?"+data #创建请求对象 req=urllib.request.Request(theurl) #获得服务器返回的数据 response=urllib.request.urlopen(req) #处理数据 page=response.read()
有2个常用的方法,geturl(),info()
geturl()的设置是为了辨别是否有服务器端的网址重定向,而info()则包含了一系列的信息。
中文问题的处理,会用到 encode()编码 dencode()解码
0 0
- Python网络爬虫(Get、Post抓取方式)
- Python网络爬虫(Get、Post抓取方式)
- Python网络爬虫(Get、Post抓取方式)
- python网络爬虫学习(一)通过GET和POST方式获取页面内容
- python网络爬虫(五):并发抓取
- python网络爬虫(1)--抓取图片
- Spider网络爬虫学习——通过Get、Post方法直接抓取网页内容
- python网络爬虫抓取图片
- python 网络爬虫抓取图片
- python网络爬虫抓取图片
- python网络爬虫抓取图片
- python网络爬虫抓取图片
- 网络请求方式 POST + GET
- python网络爬虫(1)--抓取图片(2)
- Python网络爬虫(4)煎蛋网妹子图片抓取
- Python网络爬虫(5)糗事百科段子抓取
- Python爬虫中的Get和Post方法
- python-网络爬虫初学一:获取网页源码以及发送POST和GET请求
- Android 编译流程
- SQL中distinct与order by联合使用应该注意的问题
- phpMySQL录入数据
- vs+qt+VAssistX搭建
- 编译安卓源码
- Python网络爬虫(Get、Post抓取方式)
- 常用LINUX命令
- android的四大组件
- PHP编程中10个最常见的错误
- 密码框的提示信息的显示问题
- mac 上开发环境的安装(djang, git , virtualenv)
- ios nil、NULL和NSNull 的使用
- [js编程题]添加元素
- tar.xz文件如何解压