首页 > 开发 > Python > 正文

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

2020-07-28 14:14:20
字体:
来源:转载
供稿:网友

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

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

#!user/bin/python

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

post请求:

#导入工具,内置的库import urllibimport 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.urlprint response.codeprint response.read()

get请求:

#导入工具,内置的库import urllibimport 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.urlprint response.codeprint response.read()

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

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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表