liansai.py 1.8 KB

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