zuqiu.py 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. # -*- coding: utf-8 -*-
  2. import scrapy
  3. class ZuqiuSpider(scrapy.Spider):
  4. name = 'zuqiu'
  5. allowed_domains = ['m.hgg070.com']
  6. # 读取今日足球
  7. def start_requests(self):
  8. headers = {
  9. 'Accept': '*/*',
  10. 'Accept-Encoding': 'gzip, deflate',
  11. 'Accept-Language': 'zh-CN,zh;q=0.9',
  12. 'Content-Length': '130',
  13. 'Content-type': 'application/x-www-form-urlencoded',
  14. 'Cookie': '_ga=GA1.2.1009358217.1572056223; _gid=GA1.2.97506800.1572056223; _gat=1',
  15. 'Host': 'm.hgg070.com',
  16. 'Origin': 'http://m.hgg070.com',
  17. 'Proxy-Connection': 'keep-alive',
  18. 'Referer': 'http://m.hgg070.com/',
  19. 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
  20. }
  21. url = "http://m.hgg070.com/app/member/get_league_list.php"
  22. h_types = [('FT', '', '130'), ('FU', 'P', '131'), ('FU', "", '130'), ('FU', '', '131')]
  23. for h_type in h_types:
  24. show_type, isp, length = h_type
  25. headers['Content-Length'] = length
  26. from_data = {
  27. 'uid': '4f6573b99cc31f7be1579b063888a8a2bcda122ce94228510cda9e1bb32a477f',
  28. 'langx': 'zh-cn',
  29. 'ltype': '3',
  30. 'gtype': 'FT',
  31. 'showtype': show_type,
  32. 'sorttype': '',
  33. 'date': '',
  34. 'isP': isp
  35. }
  36. yield scrapy.FormRequest(url=url, formdata=from_data, callback=self.parse, headers=headers,
  37. meta={'showtype': show_type, 'isp': isp}, dont_filter=True)
  38. def parse(self, response):
  39. leagues = response.xpath('//serverresponse/game/league')
  40. url = 'http://m.hgg070.com/app/member/get_game_list.php'
  41. headers = {
  42. 'Accept': '*/*',
  43. 'Accept-Encoding': 'gzip, deflate',
  44. 'Accept-Language': 'zh-CN,zh;q=0.9',
  45. 'Content-Length': '147',
  46. 'Content-type': 'application/x-www-form-urlencoded',
  47. 'Cookie': '_ga=GA1.2.1009358217.1572056223; _gid=GA1.2.97506800.1572056223; _gat=1',
  48. 'Host': 'm.hgg070.com',
  49. 'Origin': 'http://m.hgg070.com',
  50. 'Proxy-Connection': 'keep-alive',
  51. 'Referer': 'http://m.hgg070.com/',
  52. 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.38 (KHTML, like Gecko) Version/11.0 Mobile/15A372 Safari/604.1'
  53. }
  54. if leagues:
  55. showtype = response.meta['showtype']
  56. isp = response.meta['isp']
  57. if showtype == 'FT' and isp == '':
  58. date = ''
  59. headers['Content-Length'] = '147'
  60. elif showtype == 'FU' and isp == 'P':
  61. date = 'all'
  62. headers['Content-Length'] = '151'
  63. elif showtype == 'FU' and isp == '':
  64. date = 'all'
  65. headers['Content-Length'] = '150'
  66. else:
  67. date = 'all'
  68. headers['Content-Length'] = '151'
  69. for league in leagues:
  70. lid = league.xpath('.//league_id/text()').extract_first()
  71. from_data = {
  72. 'uid': '4f6573b99cc31f7be1579b063888a8a2bcda122ce94228510cda9e1bb32a477f',
  73. 'langx': 'zh-cn',
  74. 'ltype': '3',
  75. 'gtype': 'FT',
  76. 'showtype': showtype,
  77. # 'showtype': "FT",
  78. # 'lid': '103391',
  79. 'lid': lid,
  80. 'sorttype': 'league',
  81. 'date': date,
  82. 'isP': isp
  83. # 'date': "",
  84. # 'isP': ""
  85. }
  86. yield scrapy.FormRequest(url=url, formdata=from_data, callback=self.parse_match, headers=headers,
  87. meta={'showtype': showtype, 'isp': isp}, dont_filter=True)
  88. def parse_match(self, response):
  89. print(response.text)
  90. pass