Python爬虫开发-02--POST请求的爬虫模型

    与GET方式的区别在于:增加了请求数据。
import urllib
import urllib2
url = 'http://www.zhihu.com/signup?next=%2F'
postdata = {'username ': 'qiye', 'password': 'qiyepass'}
data = urllib.urlencode(postdata)
req = urllib2.Request(url, data)
response = urllib2.urlopen(req)

html = response.read()
print html

    但是有时候会出现一种情况是:即使POST请求的数据是对的,但是服务器拒绝你的访问。

    为什么?问题就出在请求的头信息中,服务器会检验请求头,来判断是否是来自浏览器的访问,这也是反爬虫的常用手段。

    至于请求头Headers处理,后续我在深入学习。

猜你喜欢

转载自blog.csdn.net/sarline/article/details/80280457