roll_zuqiu.py 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469
  1. # -*- coding: utf-8 -*-
  2. import copy
  3. import datetime
  4. import json
  5. # import jsonpath
  6. import scrapy
  7. from scrapy.http import Request
  8. from ..items import Roll_Zuqiu
  9. class ZuqiuSpider(scrapy.Spider):
  10. name = 'roll_zuqiu'
  11. to_day = datetime.datetime.now()
  12. allowed_domains = ['hg3535z.com']
  13. custom_settings = {
  14. "ITEM_PIPELINES":{
  15. 'hg3535.pipeline.roll_zuqiu.Roll_Zuqiupipeline': 200,
  16. },
  17. # 'LOG_LEVEL': 'DEBUG',
  18. # 'LOG_FILE': "../hg3535/log/roll_zuqiu_{}_{}_{}.log".format(to_day.year, to_day.month,to_day.day)
  19. }
  20. start_urls = ['https://odata.jiushan6688.com/odds6i/d/getodds/zh-cn/sid/1/pt/4/ubt/am/pn/0/sb/2/dc/null/pid/0']
  21. def parse(self, response):
  22. responses = json.loads(response.text)
  23. try:
  24. datas = responses["i-ot"]
  25. except:
  26. print("暂无滚球篮球数据")
  27. return
  28. if datas:
  29. for data in datas:
  30. egs = data.get('egs')
  31. if egs:
  32. for es in egs:
  33. es = es['es']
  34. for e in es:
  35. match_id = str(e['i'][16])
  36. url = 'https://odata.jiushan6688.com/odds6i/d/getamodds/zh-cn/eid/{}/iip/true/ubt/am/isp/false'.format(match_id)
  37. yield Request(url=url, callback=self.parse_each, dont_filter=True)
  38. else:
  39. print('足球滚球数据为空')
  40. else:
  41. print("暂无滚球足球数据")
  42. return
  43. def parse_each(self, response):
  44. # 球队进球数 大小
  45. try:
  46. datas = json.loads(response.text)['eg']['es']
  47. league_id = json.loads(response.text)['eg']['c']['k']
  48. # 联赛名
  49. league_name = json.loads(response.text)['eg']['c']['n']
  50. except:
  51. datas = ""
  52. league_id = ""
  53. # 联赛名
  54. league_name = ""
  55. if datas:
  56. item = Roll_Zuqiu()
  57. full_dict = {}
  58. half_dict = {}
  59. full_dict_rule = {}
  60. half_dict_rule = {}
  61. for data in datas:
  62. try:
  63. new_data = data['pci']['ctid']
  64. except:
  65. new_data = ""
  66. if new_data == 0:
  67. # 比赛id
  68. game_id = str(data['k'])
  69. # 球队1
  70. team_home = data['i'][0]
  71. # 球队2
  72. team_guest = data['i'][1]
  73. # 数量(97>)
  74. number = data['i'][2]
  75. # 下半场
  76. half_way = data['i'][12]
  77. # 角球或者其他
  78. corner_ball = data['pci'].get('ctn', "")
  79. # 日期
  80. data_game = data['i'][4]
  81. # 开赛时间
  82. time_game = data['i'][5]
  83. #这个地方的值不准确 需要再次确认
  84. score_home = data['i'][10] # 队一分数
  85. score_guest = data['i'][11] # 队二分数
  86. # half_way = new_result['i'][12] #下半场
  87. # 让球------------------------------------------------------------------------------------------------------------------
  88. try:
  89. concedes = data['o']['ah']['v']
  90. new_concedes = [concedes[i] for i in range(len(concedes)) if i % 2 == 1]
  91. concede_homes = [new_concedes[i] for i in range(len(new_concedes)) if i % 2 == 0]
  92. concede_home_rule = [concede_homes[i] for i in range(len(concede_homes)) if i % 2 == 0]
  93. concede_home = [concede_homes[i] for i in range(len(concede_homes)) if i % 2 is 1]
  94. concede_guests = [new_concedes[i] for i in range(len(new_concedes)) if i % 2 is 1]
  95. # concede_guest_rule
  96. # concede_guest
  97. concede_guest_rule = [concede_guests[i] for i in range(len(concede_guests)) if i % 2 == 0]
  98. concede_guest = [concede_guests[i] for i in range(len(concede_guests)) if i % 2 is 1]
  99. except:
  100. concede_guest = ""
  101. concede_guest_rule = ""
  102. concede_home = ""
  103. concede_home_rule = ""
  104. # 上半场让球half_concede-------------------------------------------------------------------------------------------------
  105. try:
  106. half_concedes = data['o']['ah1st']['v']
  107. new_half_concedes = [half_concedes[i] for i in range(len(half_concedes)) if i % 2 is 1]
  108. new_half_concede_homes = [new_half_concedes[i] for i in range(len(new_half_concedes)) if
  109. i % 2 is 0]
  110. half_concede_guest_rule = [new_half_concede_homes[i] for i in range(len(new_half_concede_homes)) if i % 2 == 0]
  111. # concede_home
  112. half_concede_home = [new_half_concede_homes[i] for i in range(len(new_half_concede_homes)) if i % 2 is 1]
  113. half_concede_guests = [new_half_concedes[i] for i in range(len(new_half_concedes)) if i % 2 is 1]
  114. half_concede_home_rule = [half_concede_guests[i] for i in range(len(half_concede_guests)) if i % 2 == 0]
  115. # concede_guest
  116. half_concede_guest = [half_concede_guests[i] for i in range(len(half_concede_guests)) if
  117. i % 2 is 1]
  118. except:
  119. half_concede_home_rule = ""
  120. half_concede_home = ""
  121. half_concede_guest_rule = ""
  122. half_concede_guest = ""
  123. # 全场大小size 进球大小---------------------------------------------------------------------------------------------------
  124. try:
  125. sizes = data['o']['ou']['v']
  126. new_sizes = [sizes[i] for i in range(len(sizes)) if i % 2 is 1]
  127. size_homes = [new_sizes[i] for i in range(len(new_sizes)) if i % 2 is 0]
  128. # size_home_rule
  129. size_home_rule = [size_homes[i] for i in range(len(size_homes)) if i % 2 is 0]
  130. # size_home
  131. size_home = [size_homes[i] for i in range(len(size_homes)) if i % 2 is 1]
  132. size_guests = [new_sizes[i] for i in range(len(new_sizes)) if i % 2 is 1]
  133. # size_guest_rule
  134. size_guest_rule = [size_guests[i] for i in range(len(size_guests)) if i % 2 is 0]
  135. # csize_guest
  136. size_guest = [size_guests[i] for i in range(len(size_guests)) if i % 2 is 1]
  137. except:
  138. size_guest = ""
  139. size_guest_rule = ""
  140. size_home = ""
  141. size_home_rule = ""
  142. # 上半场大小 进球大小 half_size-------------------------------------------------------------------------------------------
  143. try:
  144. half_sizes = data['o']['ou1st']['v']
  145. new_half_sizes = [half_sizes[i] for i in range(len(half_sizes)) if i % 2 is 1]
  146. half_size_homes = [new_half_sizes[i] for i in range(len(new_half_sizes)) if i % 2 is 0]
  147. # size_home_rule
  148. half_size_home_rule = [half_size_homes[i] for i in range(len(half_size_homes)) if i % 2 is 0]
  149. # half_size_home 主队
  150. half_size_home = [half_size_homes[i] for i in range(len(half_size_homes)) if i % 2 is 1]
  151. half_size_guests = [new_half_sizes[i] for i in range(len(new_half_sizes)) if i % 2 is 1]
  152. # half_size_guest_rule 客队
  153. half_size_guest_rule = [half_size_guests[i] for i in range(len(half_size_guests)) if i % 2 is 0]
  154. # half_size_guest
  155. half_size_guest = [half_size_guests[i] for i in range(len(half_size_guests)) if
  156. i % 2 is 1]
  157. except:
  158. half_size_guest = ""
  159. half_size_guest_rule = ""
  160. half_size_home = ""
  161. half_size_home_rule = ""
  162. # 全场总进球 total_goal--------------------------------------------------------------------------------------------------
  163. total_goal = {}
  164. try:
  165. total_goals = data['o']['tg']['v']
  166. new_total_goals = [total_goals[i] for i in range(len(total_goals)) if i % 2 is 1]
  167. total_goal["tg0"] = round(float(new_total_goals[0]) - 1, 2)
  168. total_goal["tg1"] = round(float(new_total_goals[1]) - 1, 2)
  169. total_goal["tg2"] = round(float(new_total_goals[2]) - 1, 2)
  170. total_goal["tg3"] = round(float(new_total_goals[3]) - 1, 2)
  171. except:
  172. total_goal["tg0"] = ""
  173. total_goal["tg1"] = ""
  174. total_goal["tg2"] = ""
  175. total_goal["tg3"] = ""
  176. # 总进球上半场 half_total_goal-------------------------------------------------------------------------------------------
  177. try:
  178. half_total_goals = data['o']['tg1st']['v']
  179. new_half_total_goals = [half_total_goals[i] for i in range(len(half_total_goals)) if i % 2 is 1]
  180. total_goal["tg0_h"] = round(float(new_half_total_goals[0]) - 1, 2)
  181. total_goal["tg1_h"] = round(float(new_half_total_goals[1]) - 1, 2)
  182. total_goal["tg2_h"] = round(float(new_half_total_goals[2]) - 1, 2)
  183. total_goal["tg3_h"] = round(float(new_half_total_goals[3]) - 1, 2)
  184. except:
  185. total_goal["tg0_h"] = ""
  186. total_goal["tg1_h"] = ""
  187. total_goal["tg2_h"] = ""
  188. total_goal["tg3_h"] = ""
  189. # 早盘 半场/全场---------------------------------------------------------------------------------------------------------
  190. half_full = {}
  191. new_lists = ["hfhh", "hfhd", "hfhg", "hfdh", "hfdd", "hfdg", "hfgh", "hfgd", "hfgg"]
  192. # 早盘 半场/全场
  193. try:
  194. half_fulls = data['o']['hf']['v']
  195. new_half_fulls = [half_fulls[i] for i in range(len(half_fulls)) if i % 2 is 1]
  196. for index, value in enumerate(new_lists):
  197. half_full[value] = round(float(new_half_fulls[index]) - 1, 2)
  198. except:
  199. for index, value in enumerate(new_lists):
  200. half_full[value] = ""
  201. # 早盘 最先/最后进球 最先进球 ---------------------------------------------------------------------------------------------
  202. first_last_ball = {}
  203. try:
  204. first_balls = data['o']['ttslast']['v']
  205. first_ball = [first_balls[i] for i in range(len(first_balls)) if i % 2 is 1]
  206. first_last_ball['flbfh'] = round(float(first_ball[0]) - 1, 2)
  207. first_last_ball['flbfg'] = round(float(first_ball[1]) - 1, 2)
  208. except:
  209. pass
  210. # 早盘 最先/最后进球 最后进球
  211. try:
  212. last_balls = data['o']['tts1st']['v']
  213. last_ball = [last_balls[i] for i in range(len(last_balls)) if i % 2 is 1]
  214. first_last_ball['flblh'] = round(float(last_ball[0]) - 1, 2)
  215. first_last_ball['flblg'] = round(float(last_ball[1]) - 1, 2)
  216. first_last_ball['flbn'] = round(float(last_ball[2]) - 1, 2)
  217. except:
  218. pass
  219. # 全场独赢capot ---------------------------------------------------------------------------------------------------------
  220. try:
  221. capots = data['o']['1x2']['v']
  222. new_capots = [capots[i] for i in range(len(capots)) if i % 2 is 1]
  223. capot_home = round(float(new_capots[0]) - 1, 2)
  224. capot_guest = round(float(new_capots[1]) - 1, 2)
  225. capot_dogfall = round(float(new_capots[2]) - 1, 2)
  226. except:
  227. capot_home = ""
  228. capot_guest = ""
  229. capot_dogfall = ""
  230. # 上半场独赢capot
  231. try:
  232. half_capots = data['o']['1x21st']['v']
  233. new_half_capots = [half_capots[i] for i in range(len(half_capots)) if i % 2 is 1]
  234. half_capot_home = round(float(new_half_capots[0]) - 1, 2)
  235. half_capot_guest = round(float(new_half_capots[1]) - 1, 2)
  236. half_capot_dogfall = round(float(new_half_capots[2]) - 1, 2)
  237. except:
  238. half_capot_home = ""
  239. half_capot_guest = ""
  240. half_capot_dogfall = ""
  241. # 全场入球:单/双 odd_even------------------------------------------------------------------------------------------------
  242. try:
  243. odd_evens = data['o']['oe']['v']
  244. new_odd_evens = [odd_evens[i] for i in range(len(odd_evens)) if i % 2 is 1]
  245. odd_even_odd = new_odd_evens[0]
  246. odd_even_even = new_odd_evens[1]
  247. except:
  248. odd_even_odd = ""
  249. odd_even_even = ""
  250. # 半场入球:单/双 half_odd_even
  251. try:
  252. half_odd_evens = data['o']['oe1st']['v']
  253. new_half_odd_evens = [half_odd_evens[i] for i in range(len(half_odd_evens)) if i % 2 is 1]
  254. half_odd_even_odd = new_half_odd_evens[0]
  255. half_odd_even_even = new_half_odd_evens[1]
  256. except:
  257. half_odd_even_odd = ""
  258. half_odd_even_even = ""
  259. bodan_data = {}
  260. # 波胆------------------------------------------------------------------------------------------------------------------
  261. try:
  262. bodans = data['o']['cs']['v']
  263. one_list = ["b10", "b20", "b21", "b30", "b31", "b32", "b40", "b41", "b42", "b43"]
  264. two_list = ["b01", "b02", "b12", "b03", "b13", "b23", "b04", "b14", "b24", "b34"]
  265. three_list = ["b00", "b11", "b22", "b33", "b44"]
  266. new_bodans = [bodans[i] for i in range(len(bodans)) if i % 2 is 1]
  267. new_bodan = new_bodans[0:20]
  268. # 主队bodan_home
  269. bodan_home = [new_bodan[i] for i in range(len(new_bodan)) if i % 2 is 0]
  270. for index, t in enumerate(one_list):
  271. bodan_data[t] = round(float(bodan_home[index]) - 1, 2)
  272. # 客队bodan_guest
  273. bodan_guest = [new_bodan[i] for i in range(len(new_bodan)) if i % 2 is 1]
  274. for y, z in enumerate(two_list):
  275. bodan_data[z] = round(float(bodan_guest[y]) - 1, 2)
  276. bodan_dogfall = new_bodans[-7:-2]
  277. for a, b in enumerate(three_list):
  278. bodan_data[b] = round(float(bodan_dogfall[a]) - 1, 2)
  279. # 其他bodan_other
  280. bodan_data['bo'] = round(float(new_bodans[-1]) - 1, 2)
  281. except:
  282. pass
  283. try:
  284. half_bodans = data['o']['cs1st']['v']
  285. new_half_bodans = [half_bodans[i] for i in range(len(half_bodans)) if i % 2 is 1]
  286. new_one = ["b10_h", "b20_h", "b21_h", "b30_h", "b31_h", "b32_h"]
  287. new_two = ["b01_h", "b02_h", "b12_h", "b03_h", "b13_h", "b23_h"]
  288. new_three = ["b00_h", "b11_h", "b22_h", "b33_h"]
  289. halfbodan = new_half_bodans[0:12]
  290. half_bodan_home = [halfbodan[i] for i in range(len(halfbodan)) if i % 2 is 0]
  291. # 队1
  292. for index, t in enumerate(new_one):
  293. bodan_data[t] = round(float(half_bodan_home[index]) - 1, 2)
  294. # 队2
  295. half_bodan_guest = [halfbodan[i] for i in range(len(halfbodan)) if i % 2 is 1]
  296. for y, z in enumerate(new_two):
  297. bodan_data[z] = round(float(half_bodan_guest[y]) - 1, 2)
  298. # 和/平
  299. half_bodan_dogfall = new_half_bodans[-6:-2]
  300. for a, b in enumerate(new_three):
  301. bodan_data[b] = round(float(half_bodan_dogfall[a]) - 1, 2)
  302. # 其他
  303. bodan_data['bo_h'] = round(float(new_half_bodans[-1]) - 1, 2)
  304. except:
  305. pass
  306. if new_data == 12:
  307. try:
  308. home_data = data['o']['ou']['v']
  309. # 球队进球 大条件
  310. full_dict_rule['tbhb'] = home_data[1]
  311. # 球队进球小条件
  312. full_dict_rule['tbhs'] = home_data[3]
  313. # 球队进球大赔率
  314. full_dict['tbhb'] = home_data[5]
  315. # 球队进球小赔率
  316. full_dict['tbhs'] = home_data[7]
  317. except:
  318. full_dict['tbhs'] = ""
  319. full_dict_rule['tbhs'] = ""
  320. full_dict['tbhb'] = ""
  321. full_dict_rule['tbhb'] = ""
  322. try:
  323. half_home_data = data['o']['ou1st']['v']
  324. half_dict_rule['tbhb_h'] = half_home_data[1]
  325. half_dict_rule['tbhs_h'] = half_home_data[3]
  326. half_dict['tbhb_h'] = half_home_data[5]
  327. half_dict['tbhs_h'] = half_home_data[7]
  328. except:
  329. half_dict_rule['tbhb_h'] = ""
  330. half_dict['tbhb_h'] = ""
  331. half_dict_rule['tbhs_h'] = ""
  332. half_dict['tbhs_h'] = ""
  333. if new_data == 13:
  334. try:
  335. guest_data = data['o']['ou']['v']
  336. #
  337. # guest_size_big_rule = guest_data[1]
  338. # full_dict_rule['guest_tema_ball_big'] = guest_size_big_rule
  339. #
  340. # guest_size_big = guest_data[5]
  341. # full_dict['guest_tema_ball_big'] = guest_size_big
  342. #
  343. # guest_size_small_rule = guest_data[3]
  344. # full_dict_rule['guest_tema_ball_small'] = guest_size_small_rule
  345. #
  346. # guest_size_small = guest_data[7]
  347. # full_dict['guest_tema_ball_small'] = guest_size_small
  348. full_dict_rule['tbgb'] = guest_data[1]
  349. full_dict_rule['tbgs'] = guest_data[3]
  350. full_dict['tbgb'] = guest_data[5]
  351. full_dict['tbgs'] = guest_data[7]
  352. except:
  353. full_dict_rule['tbgb'] = ""
  354. full_dict['tbgb'] = ""
  355. full_dict_rule['tbgs'] = ""
  356. full_dict['tbgs'] = ''
  357. try:
  358. half_guest_data = data['o']['ou1st']['v']
  359. # half_guest_size_big_rule = half_guest_data[1]
  360. # half_dict_rule['half_guest_tema_ball_big'] = half_guest_size_big_rule
  361. #
  362. # half_guest_size_big = half_guest_data[5]
  363. # half_dict['half_guest_tema_ball_big'] = half_guest_size_big
  364. #
  365. # half_guest_size_small_rule = half_guest_data[3]
  366. # half_dict_rule['half_guest_tema_ball_small'] = half_guest_size_small_rule
  367. #
  368. # half_guest_size_small = half_guest_data[7]
  369. # half_dict['half_guest_tema_ball_small'] = half_guest_size_small
  370. half_dict_rule['tbgb_h'] = half_guest_data[1]
  371. half_dict_rule['tbgs_h'] = half_guest_data[3]
  372. half_dict['tbgb_h'] = half_guest_data[5]
  373. half_dict['tbgs_h'] = half_guest_data[7]
  374. except:
  375. half_dict_rule['tbgb_h'] = ""
  376. half_dict['tbgb_h'] = ""
  377. half_dict_rule['tbgs_h'] = ""
  378. half_dict['tbgs_h'] = ""
  379. item['league_id'] = league_id
  380. item['league_name'] = league_name
  381. item['game_id'] = game_id
  382. item['team_home'] = team_home
  383. item['team_guest'] = team_guest
  384. item['number'] = number
  385. item['data_game'] = data_game
  386. item['time_game'] = time_game
  387. item['corner_ball'] = corner_ball
  388. # 波胆
  389. item['bodan_data'] = bodan_data
  390. # 早盘入球数单双
  391. item["odd_even_odd"] = odd_even_odd
  392. item["odd_even_even"] = odd_even_even
  393. item["half_odd_even_odd"] = half_odd_even_odd
  394. item["half_odd_even_even"] = half_odd_even_even
  395. item['total_goal'] = total_goal
  396. item["half_capot_home"] = half_capot_home
  397. item["half_capot_guest"] = half_capot_guest
  398. item["half_capot_dogfall"] = half_capot_dogfall
  399. item["capot_home"] = capot_home
  400. item["capot_guest"] = capot_guest
  401. item["capot_dogfall"] = capot_dogfall
  402. item["first_last_ball"] = first_last_ball
  403. item["half_full"] = half_full
  404. item["half_size_guest"] = half_size_guest
  405. item["half_size_guest_rule"] = half_size_guest_rule
  406. item["half_size_home"] = half_size_home
  407. item["half_size_home_rule"] = half_size_home_rule
  408. # 全场大小
  409. item["size_guest"] = size_guest
  410. item["size_guest_rule"] = size_guest_rule
  411. item["size_home"] = size_home
  412. item["size_home_rule"] = size_home_rule
  413. # 上半场让球
  414. item["half_concede_home_rule"] = half_concede_home_rule
  415. item["half_concede_home"] = half_concede_home
  416. item["half_concede_guest_rule"] = half_concede_guest_rule
  417. item["half_concede_guest"] = half_concede_guest
  418. # 全场让球
  419. item["concede_guest"] = concede_guest
  420. item["concede_guest_rule"] = concede_guest_rule
  421. item["concede_home"] = concede_home
  422. item["concede_home_rule"] = concede_home_rule
  423. item['score_home'] = score_home
  424. item['score_guest'] = score_guest
  425. item['full_data'] = full_dict
  426. item['half_data'] = half_dict
  427. item['full_data_rule'] = full_dict_rule
  428. item['half_data_rule'] = half_dict_rule
  429. item['half_way'] = half_way
  430. yield item