liansai.py 1.8 KB

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