lanqiu.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. # -*- coding: utf-8 -*-
  2. import scrapy
  3. import re
  4. import copy
  5. class LanqiuSpider(scrapy.Spider):
  6. name = 'lanqiu'
  7. allowed_domains = ['m.hgg070.com/']
  8. start_urls = ['http://m.hgg070.com//']
  9. remath=re.compile("篮球")
  10. # custom_settings={
  11. # "ITEM_PIPELINES": {
  12. # "collectSports.pipelines.zuqiu.ZuqiuPipeline": 200,
  13. # },
  14. # }
  15. def start_requests(self):
  16. #今日,早盘
  17. h_types=[('FT'),('FU')]
  18. headers = {
  19. 'Accept': '*/*',
  20. 'Accept-Encoding': 'gzip, deflate',
  21. 'Accept-Language': 'zh-CN,zh;q=0.9',
  22. 'Connection': 'keep-alive',
  23. 'Content-Length': '130',
  24. 'Content-type': 'application/x-www-form-urlencoded',
  25. 'Cookie': '_ga=GA1.2.471918301.1572059707; _gid=GA1.2.2109447865.1572059707; _gat=1',
  26. 'Host': 'm.hgg070.com',
  27. 'Origin': 'http://m.hgg070.com',
  28. 'Referer': 'http://m.hgg070.com/',
  29. 'User-Agent': 'Mozilla/5.0 (Linux; Android 6.0; Nexus 5 Build/MRA58N) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.70 Mobile Safari/537.36'
  30. }
  31. url = "http://m.hgg070.com/app/member/get_league_list.php"
  32. for item in h_types:
  33. showtype = item
  34. data={
  35. 'uid': '9b9f0dea34ee4e5225990433370a88fea2b37b79c98e266b338152c619a71d2b',
  36. 'langx': 'zh-cn',
  37. 'ltype': '3',
  38. 'gtype': 'BK',
  39. 'showtype': showtype,
  40. 'sorttype': '',
  41. 'date': '',
  42. 'isP': ''
  43. }
  44. yield scrapy.FormRequest(url=url,formdata=data,callback=self.parse,headers=headers,
  45. meta={"data":data}, dont_filter=True)
  46. def parse(self, response):
  47. #获取id并判断抓取的球型
  48. data=response.meta["data"]
  49. fromdata=copy.deepcopy(data)
  50. league=response.xpath('//league')
  51. url="http://m.hgg070.com/app/member/get_game_list.php"
  52. for le in league:
  53. name=le.xpath('./league_name/text()').extract_first()
  54. if len(self.remath.findall(name))>0:
  55. lid = le.xpath('./league_id/text()').extract_first()
  56. # 抓取今日
  57. if data["showtype"]=="FT":
  58. data['lid'],data['sorttype'],data['date']=lid,'league',''
  59. # 抓取早盘
  60. elif data["showtype"]=="FU":
  61. data['lid'], data['sorttype'], data['date'] = lid, 'league', 'all'
  62. yield scrapy.FormRequest(url=url,formdata=data,callback=self.detailball,meta={"data":fromdata},dont_filter=True)
  63. def detailball(self,response):
  64. data=response.meta["data"]
  65. url="http://m.hgg070.com/app/member/get_game_more.php"
  66. #获取联赛id gid
  67. game=response.xpath("//game")
  68. for g in game:
  69. gid=g.xpath("./gid/text()").extract_first()
  70. data["gid"]=gid
  71. print('wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww',data)
  72. yield scrapy.FormRequest(url=url,formdata=data,callback=self.getItem,dont_filter=True)
  73. def getItem(self,response):
  74. print('ffffffffffffffffffffffffffffffffffffffffffffffffffffff',response.text)