roll_zuqiu.py 26 KB

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