jieshu.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import datetime
  2. import json
  3. # import re
  4. import logging
  5. import redis
  6. import scrapy
  7. from ..items import Hgjieshu
  8. class HgjieshuSpider(scrapy.Spider):
  9. name = 'jieshu'
  10. to_day = datetime.datetime.now()
  11. allowed_domains = ['hg3535z.com']
  12. custom_settings = {
  13. "ITEM_PIPELINES": {
  14. 'hg3535.pipeline.jieshu.Jieshuqiupipeline': 300,
  15. },
  16. # 'LOG_LEVEL': 'DEBUG',
  17. # 'LOG_FILE': "../hg3535/log/saiguo{}_{}_{}.log".format(to_day.year, to_day.month, to_day.day)
  18. }
  19. rls = redis.Redis(host='192.168.2.200', port=6379, db=1, password=123456)
  20. def start_requests(self):
  21. match_ids = self.rls.smembers("hg3535.gunqiu.ids")
  22. if match_ids:
  23. for match_id in match_ids:
  24. match_id = match_id.decode()
  25. url = 'https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/{}/iip/true/ubt/am/isp/false'.format(match_id)
  26. yield scrapy.Request(url=url, callback=self.parse, dont_filter=True)
  27. def parse(self, response):
  28. logger = logging.getLogger(__name__)
  29. try:
  30. data = json.loads(response.text)
  31. status = data['i'][0]
  32. if not status:
  33. ball = data['i'][31]
  34. match_id = data['i'][2]
  35. # self.rls.srem('hg3535.zq.gunqiu', data)
  36. item = Hgjieshu()
  37. item['ball'] = ball
  38. item['match_id'] = match_id
  39. yield item
  40. except Exception as e:
  41. logger.warning(e)
  42. return