roll_zuqiu.py 26 KB

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