python获取和重用sessionokie帮助?

2024-04-28 20:37:03 发布

您现在位置:Python中文网/ 问答频道 /正文

所以我试着从12bet.co.uk公司. 我有以下针对我想要的信息的python代码:

import urllib2
sid = 'lgvvtb45xlqtwe45wjp3wy45'  # value copied from a Firefox session
url = 'http://eu.12bet.co.uk/EuroSite/Match_data.aspx?Scope=Sport&Id=1&Sport=1&Market=d&RT=W&Game=0&OddsType=1'
http_req_data = None
http_req_header = {'User-Agent' : 'Mozilla/5.0 (Windows NT 5.1; rv:12.0) Gecko/20100101 Firefox/12.0',
    'Accept' : 'text/html',
    'Accept-Language' : 'en-us,en;q=0.5',
    'DNT' : '1',
    'Referer' : 'http://eu.12bet.co.uk/EuroSite/Euro_index.aspx',
    'Cookie' : 'MuSou_eu=20110303; iom_territory=UK; LangKey=en; OddsType_12BETUUS01015=1; ASP.NET_SessionId='+sid+'',
    'Connection' : 'keep-alive'}
web_req = urllib2.Request(url, http_req_data, http_req_header)  # create request object
web_resp = urllib2.urlopen(web_req)  # open the request object and return a handle
print web_resp.info()

当我从Firefox会话中复制/粘贴sid值时,这个方法工作得很好(Content Length is large=返回大量漂亮的内容)。 但是,如果我试图通过编程方式获取sid的值,首先运行类似于以下代码的代码,那么当我使用下面代码找到的sid值运行上述代码时,我不会得到任何内容:

^{pr2}$

我已经做了很多年了,但我还是做不出来。它把我的头撞了。有谁能告诉我这里出了什么问题吗?许多提前。在


Tags: 代码webhttpurldataurllib2firefoxreq