Python Mechanize-如何在单个.open()调用中添加标头?

Python Mechanize-如何在单个.open()调用中添加标头?,第1张

Python Mechanize-如何在单个.open()调用添加标头?

像这样做:

import mechanizeimport urllib2browser = mechanize.Browser()# setup your header, add anything you wantheader = {'User-Agent': 'Mozilla/5.0 (Windows NT 5.1; rv:14.0) Gecko/20100101 Firefox/14.0.1', 'Referer': 'http://whateveritis.com'}url = "http://google.com"# wrap the request. You can replace None with the needed data if it's a POST requestrequest = urllib2.Request(url, None, header)# here you goresponse = browser.open(request)print response.geturl()print response.read()response.close()


欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/5631560.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-12-15
下一篇2022-12-15

发表评论

登录后才能评论

评论列表(0条)

    保存