Python大数据之网络爬虫的post请求、get请求区别实例分析

这篇文章主要介绍了Python大数据之网络爬虫的post请求、get请求区别,结合具体实例形式分析了Python网页爬虫post请求与get请求相关使用技巧,需要的朋友可以参考下

本文实例讲述了Python大数据之网络爬虫的post请求、get请求区别。分享给大家供大家参考,具体如下:

在JetBrains PyCharm 2016.3软件中编写代码前,需要指定python和编码方式:

 #!user/bin/python 

编码方式 :#coding=utf-8 或者 #-*-coding:utf-8-*-

post请求:

 #导入工具,内置的库 import urllib import urllib2 #加一个\可以换行 #response = \ #urllib2.urlopen("https://hao.360.cn/?wd_xp1") #print response.read() request = urllib2.Request('http://www.baidu.com') #response = urllib2.urlopen(request) #构造post请求 params={} params['account']='jredu' params['pwd']='' #对数据进行编码 data = urllib.urlencode(params) response = urllib2.urlopen(request,data) print response.url print response.code print response.read() 

get请求:

 #导入工具,内置的库 import urllib import urllib2 #加一个\可以换行 #response = \ #urllib2.urlopen("https://hao.360.cn/?wd_xp1") #print response.read() url='http://www.baidu.com' #response = urllib2.urlopen(request) #构造post请求 params={} params['account']='jredu' params['pwd']='' #对数据进行编码 data = urllib.urlencode(params) request = urllib2.Request(url+"?"+data) response = urllib2.urlopen(request) print response.url print response.code print response.read() 

更多关于Python相关内容可查看本站专题:《Python Socket编程技巧总结》、《Python正则表达式用法总结》、《Python数据结构与算法教程》、《Python函数使用技巧总结》、《Python字符串操作技巧汇总》、《Python入门与进阶经典教程》及《Python文件与目录操作技巧汇总

希望本文所述对大家Python程序设计有所帮助。

以上就是Python大数据之网络爬虫的post请求、get请求区别实例分析的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » python