liansai.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. }
  14. def start_requests(self):
  15. for y in range(1, 5):
  16. for i in range(1, 5):
  17. url = 'https://hg3535z.com/odds2/d/getcomps?sid='+str(y)+'&pt=' + str(i) + '&ubt=am&dc=null&pn=0&pid=0'
  18. yield scrapy.Request(url=url, callback=self.parse)
  19. def parse(self, response):
  20. try:
  21. datas = json.loads(response.text)['gs']
  22. except:
  23. datas = ""
  24. if datas:
  25. for data in datas:
  26. # 区域id,欧洲
  27. area_id = data['gid']
  28. # 区域名,欧洲
  29. area_name = data['gn']
  30. new_data = data['fc']
  31. if new_data:
  32. for i in new_data:
  33. item = Liansai()
  34. ball = json.loads(response.text)['s']
  35. st_league = i["id"]
  36. name_chinese = i['nm']
  37. item['area_id'] = area_id
  38. item['area_name'] = area_name
  39. item['st_league'] = st_league
  40. item['name_chinese'] = name_chinese
  41. item['ball'] = ball
  42. yield item