在python中发送标题 [英] Send headers along in python
本文介绍了在python中发送标题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下python脚本,我想发送假标题信息,以便我的应用程序就像是Firefox一样。我怎么能这样做?
I have the following python script and I would like to send "fake" header information along so that my application acts as if it is firefox. How could I do that?
import urllib, urllib2, cookielib
username = '****'
password = '****'
login_user = urllib.urlencode({'password' : password, 'username' : username})
jar = cookielib.FileCookieJar("cookies")
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(jar))
response = opener.open("http://www.***.com")
response = opener.open("http://www.***.com/login.php")
response = opener.open("http://www.***.com/welcome.php", login_user)
推荐答案
在开启者$ c上使用
addheaders()
函数$ c>对象。
在开始打开页面之前,只需在创建开启者后添加这一行:
Use the addheaders()
function on your opener
object.
Just add this one line after you create your opener, before you start opening pages:
opener.addheaders = [('User-agent', 'Mozilla/5.0')]
http://docs.python.org/library/urllib2.html (它位于本文档的底部)
http://docs.python.org/library/urllib2.html (it's at the bottom of this document)
这篇关于在python中发送标题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文