liansai.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. # -*- coding: utf-8 -*-
  2. import json
  3. import scrapy
  4. # from scrapy.http import Request
  5. from .. items import Liansai
  6. class LanqiulsSpider(scrapy.Spider):
  7. name = 'liansai'
  8. allowed_domains = ['hg3535z.com']
  9. custom_settings = {
  10. "ITEM_PIPELINES": {
  11. 'hg3535.pipelines.Liansaipipeline': 300,
  12. },
  13. 'LOG_LEVEL': 'DEBUG',
  14. 'LOG_FILE': '../hg3535/Log/liansai.log'
  15. }
  16. def start_requests(self):
  17. for y in range(1, 5):
  18. for i in range(1, 5):
  19. url = 'https://hg3535z.com/odds2/d/getcomps?sid='+str(y)+'&pt=' + str(i) + '&ubt=am&dc=null&pn=0&pid=0'
  20. yield scrapy.Request(url=url, callback=self.parse, dont_filter=True)
  21. # yield scrapy.Request(url=url, callback=self.parse)
  22. def parse(self, response):
  23. try:
  24. datas = json.loads(response.text)['gs']
  25. except:
  26. datas = ""
  27. if datas:
  28. for data in datas:
  29. # 区域id,欧洲
  30. area_id = data['gid']
  31. # 区域名,欧洲
  32. area_name = data['gn']
  33. new_data = data['fc']
  34. if new_data:
  35. for i in new_data:
  36. item = Liansai()
  37. ball = json.loads(response.text)['s']
  38. st_league = i["id"]
  39. name_chinese = i['nm']
  40. item['area_id'] = area_id
  41. item['area_name'] = area_name
  42. item['st_league'] = st_league
  43. item['name_chinese'] = name_chinese
  44. item['ball'] = ball
  45. yield item