roll_zuqiu.py 25 KB

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