|
|
@@ -3,6 +3,7 @@ import logging
|
|
|
import lxml
|
|
|
|
|
|
import scrapy
|
|
|
+import xmltodict
|
|
|
|
|
|
from ..items import ZuqiuItem
|
|
|
|
|
|
@@ -132,27 +133,21 @@ class ZuqiuSpider(scrapy.Spider):
|
|
|
meta={'index': index, 'tag': tag}, dont_filter=True)
|
|
|
|
|
|
def parse_odds(self, response):
|
|
|
+ logger = logging.getLogger(__name__)
|
|
|
index = response.meta['index']
|
|
|
tag = response.meta['tag']
|
|
|
- try:
|
|
|
- game = response.xpath('//serverresponse/game')[0]
|
|
|
- except:
|
|
|
+ game = xmltodict.parse(response.text)
|
|
|
+ gopen = game['serverresponse']['game']['gopen']
|
|
|
+ if gopen == 'Y':
|
|
|
+ try:
|
|
|
+ game_odds = game['serverresponse']['game'][0]
|
|
|
+ except:
|
|
|
+ game_odds = game['serverresponse']['game']
|
|
|
+ else:
|
|
|
+ logger.info('gopen == "N", 详细赔率盘口未开启')
|
|
|
return
|
|
|
- logger = logging.getLogger(__name__)
|
|
|
- if game:
|
|
|
- game_odds = {}
|
|
|
- gopen = game.xpath('//game/gopen/text()').extract_first()
|
|
|
- if gopen == 'Y':
|
|
|
- game = lxml.etree.fromstring(game.extract())
|
|
|
- for i in game.getchildren():
|
|
|
- if i.text == None:
|
|
|
- game_odds[i.tag] = ""
|
|
|
- else:
|
|
|
- game_odds[i.tag] = i.text
|
|
|
- else:
|
|
|
- logger.info('gopen == "N", 详细赔率盘口未开启')
|
|
|
- item = ZuqiuItem()
|
|
|
- item['data'] = game_odds
|
|
|
- item['index'] = index
|
|
|
- item['tag'] = tag
|
|
|
- yield item
|
|
|
+ item = ZuqiuItem()
|
|
|
+ item['data'] = game_odds
|
|
|
+ item['index'] = index
|
|
|
+ item['tag'] = tag
|
|
|
+ yield item
|