我想从http://scores.covers.com/football-scores-matchups.aspx 中爬取赔率变化。
我需要使用提供的日历来迭代每个季节和周:
当我检查网络以查看发送的内容时,我发现在更改季节时有两个POST请求:
(由于我没有足够的声望发布多个图像,所以上面的3个图像已合并为一个图像)
我需要使用提供的日历来迭代每个季节和周:
当我检查网络以查看发送的内容时,我发现在更改季节时有两个POST请求:
(由于我没有足够的声望发布多个图像,所以上面的3个图像已合并为一个图像)
http://s29.postimg.org/773muclra/covers_scrape4.jpg
我是一名有用的助手,我可以为您翻译文本。我已经搜索、阅读并且整天都在尝试解决问题,但是没有任何进展。如果我使用Firebug编辑并重新发送帖子请求,如果我编辑有效载荷以使其变得不可预期,则可以重现我遇到的错误。因此,我觉得问题在于我编码和发送数据的方式。我尝试过json.dump、utf-8、Content-Type application/x-www...,以及我能想到的每种组合。
我的当前代码如下:
import urllib.request
import json
import urllib.parse
class Scraper():
def __init__(self):
pass
def scrape(self):
url = 'http://scores.covers.com/ajax/SportsDirect.Controls.LiveScoresControls.ScoresCalendar,SportsDirect.Controls.LiveScoresControls.ashx?_method=changeDay&_session=no'
data = {
'league': '1',
'SeasonString': '2012-2013',
'Year': '1',
'Month': '1',
'Day': '1'
}
# data = urllib.parse.urlencode(data).encode('utf-8')
data = json.dumps(data).encode('utf-8')
headers = {
'Host': 'scores.covers.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 6.3; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0',
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Language': 'en-US,en;q=0.5',
'Accept-Encoding': 'gzip, deflate',
'Referer': 'http://scores.covers.com/football-scores-matchups.aspx',
'Content-Type': 'application/json',
'Connection': 'keep-alive',
'Pragma': 'no-cache',
'Cache-Control': 'no-cache'
}
req = urllib.request.Request(url)
req.data = data
req.headers = headers
f = urllib.request.urlopen(req)
print(f.read())
return f
这将给出:
In [1]: import scraper
In [2]: s = scraper.Scraper()
In [3]: s.scrape()
b"new Object();r.error = new ajax_error('System.ArgumentException','Object of type \\'System.DBNull\\' cannot be convert
ed to type \\'System.String\\'.',0)"
Out[3]: <http.client.HTTPResponse at 0x4d6b650>
提前致谢。