xigua_search_publish_time.py 48 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828
  1. # -*- coding: utf-8 -*-
  2. # @Author: wangkun
  3. # @Time: 2023/5/26
  4. import base64
  5. import json
  6. import os
  7. import random
  8. import shutil
  9. import string
  10. import sys
  11. import time
  12. from hashlib import md5
  13. import requests
  14. import urllib3
  15. from requests.adapters import HTTPAdapter
  16. from selenium.webdriver import DesiredCapabilities
  17. from selenium.webdriver.chrome.service import Service
  18. from selenium import webdriver
  19. from selenium.webdriver.common.by import By
  20. sys.path.append(os.getcwd())
  21. from common.log import Log
  22. # from common.mq import MQ
  23. from common.scheduling_db import MysqlHelper
  24. from common.common import Common
  25. from common.feishu import Feishu
  26. from common.publish import Publish
  27. from common.public import get_config_from_mysql, download_rule
  28. from common.userAgent import get_random_user_agent
  29. class XiguasearchScheduling:
  30. # 已下载视频数
  31. download_cnt = 0
  32. platform = "西瓜视频"
  33. @classmethod
  34. def random_signature(cls):
  35. src_digits = string.digits # string_数字
  36. src_uppercase = string.ascii_uppercase # string_大写字母
  37. src_lowercase = string.ascii_lowercase # string_小写字母
  38. digits_num = random.randint(1, 6)
  39. uppercase_num = random.randint(1, 26 - digits_num - 1)
  40. lowercase_num = 26 - (digits_num + uppercase_num)
  41. password = random.sample(src_digits, digits_num) + random.sample(src_uppercase, uppercase_num) + random.sample(
  42. src_lowercase, lowercase_num)
  43. random.shuffle(password)
  44. new_password = 'AAAAAAAAAA' + ''.join(password)[10:-4] + 'AAAB'
  45. new_password_start = new_password[0:18]
  46. new_password_end = new_password[-7:]
  47. if new_password[18] == '8':
  48. new_password = new_password_start + 'w' + new_password_end
  49. elif new_password[18] == '9':
  50. new_password = new_password_start + 'x' + new_password_end
  51. elif new_password[18] == '-':
  52. new_password = new_password_start + 'y' + new_password_end
  53. elif new_password[18] == '.':
  54. new_password = new_password_start + 'z' + new_password_end
  55. else:
  56. new_password = new_password_start + 'y' + new_password_end
  57. return new_password
  58. @classmethod
  59. def get_video_url(cls, video_info):
  60. video_url_dict = {}
  61. # video_url
  62. if 'videoResource' not in video_info:
  63. video_url_dict["video_url"] = ''
  64. video_url_dict["audio_url"] = ''
  65. video_url_dict["video_width"] = 0
  66. video_url_dict["video_height"] = 0
  67. elif 'dash_120fps' in video_info['videoResource']:
  68. if "video_list" in video_info['videoResource']['dash_120fps'] and 'video_4' in \
  69. video_info['videoResource']['dash_120fps']['video_list']:
  70. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
  71. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_4']['backup_url_1']
  72. if len(video_url) % 3 == 1:
  73. video_url += '=='
  74. elif len(video_url) % 3 == 2:
  75. video_url += '='
  76. elif len(audio_url) % 3 == 1:
  77. audio_url += '=='
  78. elif len(audio_url) % 3 == 2:
  79. audio_url += '='
  80. video_url = base64.b64decode(video_url).decode('utf8')
  81. audio_url = base64.b64decode(audio_url).decode('utf8')
  82. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_4']['vwidth']
  83. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_4']['vheight']
  84. video_url_dict["video_url"] = video_url
  85. video_url_dict["audio_url"] = audio_url
  86. video_url_dict["video_width"] = video_width
  87. video_url_dict["video_height"] = video_height
  88. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_3' in \
  89. video_info['videoResource']['dash_120fps']['video_list']:
  90. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
  91. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_3']['backup_url_1']
  92. if len(video_url) % 3 == 1:
  93. video_url += '=='
  94. elif len(video_url) % 3 == 2:
  95. video_url += '='
  96. elif len(audio_url) % 3 == 1:
  97. audio_url += '=='
  98. elif len(audio_url) % 3 == 2:
  99. audio_url += '='
  100. video_url = base64.b64decode(video_url).decode('utf8')
  101. audio_url = base64.b64decode(audio_url).decode('utf8')
  102. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_3']['vwidth']
  103. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_3']['vheight']
  104. video_url_dict["video_url"] = video_url
  105. video_url_dict["audio_url"] = audio_url
  106. video_url_dict["video_width"] = video_width
  107. video_url_dict["video_height"] = video_height
  108. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_2' in \
  109. video_info['videoResource']['dash_120fps']['video_list']:
  110. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
  111. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_2']['backup_url_1']
  112. if len(video_url) % 3 == 1:
  113. video_url += '=='
  114. elif len(video_url) % 3 == 2:
  115. video_url += '='
  116. elif len(audio_url) % 3 == 1:
  117. audio_url += '=='
  118. elif len(audio_url) % 3 == 2:
  119. audio_url += '='
  120. video_url = base64.b64decode(video_url).decode('utf8')
  121. audio_url = base64.b64decode(audio_url).decode('utf8')
  122. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_2']['vwidth']
  123. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_2']['vheight']
  124. video_url_dict["video_url"] = video_url
  125. video_url_dict["audio_url"] = audio_url
  126. video_url_dict["video_width"] = video_width
  127. video_url_dict["video_height"] = video_height
  128. elif "video_list" in video_info['videoResource']['dash_120fps'] and 'video_1' in \
  129. video_info['videoResource']['dash_120fps']['video_list']:
  130. video_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
  131. audio_url = video_info['videoResource']['dash_120fps']['video_list']['video_1']['backup_url_1']
  132. if len(video_url) % 3 == 1:
  133. video_url += '=='
  134. elif len(video_url) % 3 == 2:
  135. video_url += '='
  136. elif len(audio_url) % 3 == 1:
  137. audio_url += '=='
  138. elif len(audio_url) % 3 == 2:
  139. audio_url += '='
  140. video_url = base64.b64decode(video_url).decode('utf8')
  141. audio_url = base64.b64decode(audio_url).decode('utf8')
  142. video_width = video_info['videoResource']['dash_120fps']['video_list']['video_1']['vwidth']
  143. video_height = video_info['videoResource']['dash_120fps']['video_list']['video_1']['vheight']
  144. video_url_dict["video_url"] = video_url
  145. video_url_dict["audio_url"] = audio_url
  146. video_url_dict["video_width"] = video_width
  147. video_url_dict["video_height"] = video_height
  148. elif 'dynamic_video' in video_info['videoResource']['dash_120fps'] \
  149. and 'dynamic_video_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
  150. and 'dynamic_audio_list' in video_info['videoResource']['dash_120fps']['dynamic_video'] \
  151. and len(
  152. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list']) != 0 \
  153. and len(
  154. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list']) != 0:
  155. video_url = \
  156. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  157. 'backup_url_1']
  158. audio_url = \
  159. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_audio_list'][-1][
  160. 'backup_url_1']
  161. if len(video_url) % 3 == 1:
  162. video_url += '=='
  163. elif len(video_url) % 3 == 2:
  164. video_url += '='
  165. elif len(audio_url) % 3 == 1:
  166. audio_url += '=='
  167. elif len(audio_url) % 3 == 2:
  168. audio_url += '='
  169. video_url = base64.b64decode(video_url).decode('utf8')
  170. audio_url = base64.b64decode(audio_url).decode('utf8')
  171. video_width = \
  172. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  173. 'vwidth']
  174. video_height = \
  175. video_info['videoResource']['dash_120fps']['dynamic_video']['dynamic_video_list'][-1][
  176. 'vheight']
  177. video_url_dict["video_url"] = video_url
  178. video_url_dict["audio_url"] = audio_url
  179. video_url_dict["video_width"] = video_width
  180. video_url_dict["video_height"] = video_height
  181. else:
  182. video_url_dict["video_url"] = ''
  183. video_url_dict["audio_url"] = ''
  184. video_url_dict["video_width"] = 0
  185. video_url_dict["video_height"] = 0
  186. elif 'dash' in video_info['videoResource']:
  187. if "video_list" in video_info['videoResource']['dash'] and 'video_4' in \
  188. video_info['videoResource']['dash']['video_list']:
  189. video_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
  190. audio_url = video_info['videoResource']['dash']['video_list']['video_4']['backup_url_1']
  191. if len(video_url) % 3 == 1:
  192. video_url += '=='
  193. elif len(video_url) % 3 == 2:
  194. video_url += '='
  195. elif len(audio_url) % 3 == 1:
  196. audio_url += '=='
  197. elif len(audio_url) % 3 == 2:
  198. audio_url += '='
  199. video_url = base64.b64decode(video_url).decode('utf8')
  200. audio_url = base64.b64decode(audio_url).decode('utf8')
  201. video_width = video_info['videoResource']['dash']['video_list']['video_4']['vwidth']
  202. video_height = video_info['videoResource']['dash']['video_list']['video_4']['vheight']
  203. video_url_dict["video_url"] = video_url
  204. video_url_dict["audio_url"] = audio_url
  205. video_url_dict["video_width"] = video_width
  206. video_url_dict["video_height"] = video_height
  207. elif "video_list" in video_info['videoResource']['dash'] and 'video_3' in \
  208. video_info['videoResource']['dash']['video_list']:
  209. video_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
  210. audio_url = video_info['videoResource']['dash']['video_list']['video_3']['backup_url_1']
  211. if len(video_url) % 3 == 1:
  212. video_url += '=='
  213. elif len(video_url) % 3 == 2:
  214. video_url += '='
  215. elif len(audio_url) % 3 == 1:
  216. audio_url += '=='
  217. elif len(audio_url) % 3 == 2:
  218. audio_url += '='
  219. video_url = base64.b64decode(video_url).decode('utf8')
  220. audio_url = base64.b64decode(audio_url).decode('utf8')
  221. video_width = video_info['videoResource']['dash']['video_list']['video_3']['vwidth']
  222. video_height = video_info['videoResource']['dash']['video_list']['video_3']['vheight']
  223. video_url_dict["video_url"] = video_url
  224. video_url_dict["audio_url"] = audio_url
  225. video_url_dict["video_width"] = video_width
  226. video_url_dict["video_height"] = video_height
  227. elif "video_list" in video_info['videoResource']['dash'] and 'video_2' in \
  228. video_info['videoResource']['dash']['video_list']:
  229. video_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
  230. audio_url = video_info['videoResource']['dash']['video_list']['video_2']['backup_url_1']
  231. if len(video_url) % 3 == 1:
  232. video_url += '=='
  233. elif len(video_url) % 3 == 2:
  234. video_url += '='
  235. elif len(audio_url) % 3 == 1:
  236. audio_url += '=='
  237. elif len(audio_url) % 3 == 2:
  238. audio_url += '='
  239. video_url = base64.b64decode(video_url).decode('utf8')
  240. audio_url = base64.b64decode(audio_url).decode('utf8')
  241. video_width = video_info['videoResource']['dash']['video_list']['video_2']['vwidth']
  242. video_height = video_info['videoResource']['dash']['video_list']['video_2']['vheight']
  243. video_url_dict["video_url"] = video_url
  244. video_url_dict["audio_url"] = audio_url
  245. video_url_dict["video_width"] = video_width
  246. video_url_dict["video_height"] = video_height
  247. elif "video_list" in video_info['videoResource']['dash'] and 'video_1' in \
  248. video_info['videoResource']['dash']['video_list']:
  249. video_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
  250. audio_url = video_info['videoResource']['dash']['video_list']['video_1']['backup_url_1']
  251. if len(video_url) % 3 == 1:
  252. video_url += '=='
  253. elif len(video_url) % 3 == 2:
  254. video_url += '='
  255. elif len(audio_url) % 3 == 1:
  256. audio_url += '=='
  257. elif len(audio_url) % 3 == 2:
  258. audio_url += '='
  259. video_url = base64.b64decode(video_url).decode('utf8')
  260. audio_url = base64.b64decode(audio_url).decode('utf8')
  261. video_width = video_info['videoResource']['dash']['video_list']['video_1']['vwidth']
  262. video_height = video_info['videoResource']['dash']['video_list']['video_1']['vheight']
  263. video_url_dict["video_url"] = video_url
  264. video_url_dict["audio_url"] = audio_url
  265. video_url_dict["video_width"] = video_width
  266. video_url_dict["video_height"] = video_height
  267. elif 'dynamic_video' in video_info['videoResource']['dash'] \
  268. and 'dynamic_video_list' in video_info['videoResource']['dash']['dynamic_video'] \
  269. and 'dynamic_audio_list' in video_info['videoResource']['dash']['dynamic_video'] \
  270. and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list']) != 0 \
  271. and len(video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list']) != 0:
  272. video_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  273. 'backup_url_1']
  274. audio_url = video_info['videoResource']['dash']['dynamic_video']['dynamic_audio_list'][-1][
  275. 'backup_url_1']
  276. if len(video_url) % 3 == 1:
  277. video_url += '=='
  278. elif len(video_url) % 3 == 2:
  279. video_url += '='
  280. elif len(audio_url) % 3 == 1:
  281. audio_url += '=='
  282. elif len(audio_url) % 3 == 2:
  283. audio_url += '='
  284. video_url = base64.b64decode(video_url).decode('utf8')
  285. audio_url = base64.b64decode(audio_url).decode('utf8')
  286. video_width = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  287. 'vwidth']
  288. video_height = video_info['videoResource']['dash']['dynamic_video']['dynamic_video_list'][-1][
  289. 'vheight']
  290. video_url_dict["video_url"] = video_url
  291. video_url_dict["audio_url"] = audio_url
  292. video_url_dict["video_width"] = video_width
  293. video_url_dict["video_height"] = video_height
  294. else:
  295. video_url_dict["video_url"] = ''
  296. video_url_dict["audio_url"] = ''
  297. video_url_dict["video_width"] = 0
  298. video_url_dict["video_height"] = 0
  299. elif 'normal' in video_info['videoResource']:
  300. if "video_list" in video_info['videoResource']['normal'] and 'video_4' in \
  301. video_info['videoResource']['normal']['video_list']:
  302. video_url = video_info['videoResource']['normal']['video_list']['video_4']['backup_url_1']
  303. audio_url = video_info['videoResource']['normal']['video_list']['video_4']['backup_url_1']
  304. if len(video_url) % 3 == 1:
  305. video_url += '=='
  306. elif len(video_url) % 3 == 2:
  307. video_url += '='
  308. elif len(audio_url) % 3 == 1:
  309. audio_url += '=='
  310. elif len(audio_url) % 3 == 2:
  311. audio_url += '='
  312. video_url = base64.b64decode(video_url).decode('utf8')
  313. audio_url = base64.b64decode(audio_url).decode('utf8')
  314. video_width = video_info['videoResource']['normal']['video_list']['video_4']['vwidth']
  315. video_height = video_info['videoResource']['normal']['video_list']['video_4']['vheight']
  316. video_url_dict["video_url"] = video_url
  317. video_url_dict["audio_url"] = audio_url
  318. video_url_dict["video_width"] = video_width
  319. video_url_dict["video_height"] = video_height
  320. elif "video_list" in video_info['videoResource']['normal'] and 'video_3' in \
  321. video_info['videoResource']['normal']['video_list']:
  322. video_url = video_info['videoResource']['normal']['video_list']['video_3']['backup_url_1']
  323. audio_url = video_info['videoResource']['normal']['video_list']['video_3']['backup_url_1']
  324. if len(video_url) % 3 == 1:
  325. video_url += '=='
  326. elif len(video_url) % 3 == 2:
  327. video_url += '='
  328. elif len(audio_url) % 3 == 1:
  329. audio_url += '=='
  330. elif len(audio_url) % 3 == 2:
  331. audio_url += '='
  332. video_url = base64.b64decode(video_url).decode('utf8')
  333. audio_url = base64.b64decode(audio_url).decode('utf8')
  334. video_width = video_info['videoResource']['normal']['video_list']['video_3']['vwidth']
  335. video_height = video_info['videoResource']['normal']['video_list']['video_3']['vheight']
  336. video_url_dict["video_url"] = video_url
  337. video_url_dict["audio_url"] = audio_url
  338. video_url_dict["video_width"] = video_width
  339. video_url_dict["video_height"] = video_height
  340. elif "video_list" in video_info['videoResource']['normal'] and 'video_2' in \
  341. video_info['videoResource']['normal']['video_list']:
  342. video_url = video_info['videoResource']['normal']['video_list']['video_2']['backup_url_1']
  343. audio_url = video_info['videoResource']['normal']['video_list']['video_2']['backup_url_1']
  344. if len(video_url) % 3 == 1:
  345. video_url += '=='
  346. elif len(video_url) % 3 == 2:
  347. video_url += '='
  348. elif len(audio_url) % 3 == 1:
  349. audio_url += '=='
  350. elif len(audio_url) % 3 == 2:
  351. audio_url += '='
  352. video_url = base64.b64decode(video_url).decode('utf8')
  353. audio_url = base64.b64decode(audio_url).decode('utf8')
  354. video_width = video_info['videoResource']['normal']['video_list']['video_2']['vwidth']
  355. video_height = video_info['videoResource']['normal']['video_list']['video_2']['vheight']
  356. video_url_dict["video_url"] = video_url
  357. video_url_dict["audio_url"] = audio_url
  358. video_url_dict["video_width"] = video_width
  359. video_url_dict["video_height"] = video_height
  360. elif "video_list" in video_info['videoResource']['normal'] and 'video_1' in \
  361. video_info['videoResource']['normal']['video_list']:
  362. video_url = video_info['videoResource']['normal']['video_list']['video_1']['backup_url_1']
  363. audio_url = video_info['videoResource']['normal']['video_list']['video_1']['backup_url_1']
  364. if len(video_url) % 3 == 1:
  365. video_url += '=='
  366. elif len(video_url) % 3 == 2:
  367. video_url += '='
  368. elif len(audio_url) % 3 == 1:
  369. audio_url += '=='
  370. elif len(audio_url) % 3 == 2:
  371. audio_url += '='
  372. video_url = base64.b64decode(video_url).decode('utf8')
  373. audio_url = base64.b64decode(audio_url).decode('utf8')
  374. video_width = video_info['videoResource']['normal']['video_list']['video_1']['vwidth']
  375. video_height = video_info['videoResource']['normal']['video_list']['video_1']['vheight']
  376. video_url_dict["video_url"] = video_url
  377. video_url_dict["audio_url"] = audio_url
  378. video_url_dict["video_width"] = video_width
  379. video_url_dict["video_height"] = video_height
  380. elif 'dynamic_video' in video_info['videoResource']['normal'] \
  381. and 'dynamic_video_list' in video_info['videoResource']['normal']['dynamic_video'] \
  382. and 'dynamic_audio_list' in video_info['videoResource']['normal']['dynamic_video'] \
  383. and len(video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list']) != 0 \
  384. and len(video_info['videoResource']['normal']['dynamic_video']['dynamic_audio_list']) != 0:
  385. video_url = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  386. 'backup_url_1']
  387. audio_url = video_info['videoResource']['normal']['dynamic_video']['dynamic_audio_list'][-1][
  388. 'backup_url_1']
  389. if len(video_url) % 3 == 1:
  390. video_url += '=='
  391. elif len(video_url) % 3 == 2:
  392. video_url += '='
  393. elif len(audio_url) % 3 == 1:
  394. audio_url += '=='
  395. elif len(audio_url) % 3 == 2:
  396. audio_url += '='
  397. video_url = base64.b64decode(video_url).decode('utf8')
  398. audio_url = base64.b64decode(audio_url).decode('utf8')
  399. video_width = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  400. 'vwidth']
  401. video_height = video_info['videoResource']['normal']['dynamic_video']['dynamic_video_list'][-1][
  402. 'vheight']
  403. video_url_dict["video_url"] = video_url
  404. video_url_dict["audio_url"] = audio_url
  405. video_url_dict["video_width"] = video_width
  406. video_url_dict["video_height"] = video_height
  407. else:
  408. video_url_dict["video_url"] = ''
  409. video_url_dict["audio_url"] = ''
  410. video_url_dict["video_width"] = 0
  411. video_url_dict["video_height"] = 0
  412. else:
  413. video_url_dict["video_url"] = ''
  414. video_url_dict["audio_url"] = ''
  415. video_url_dict["video_width"] = 0
  416. video_url_dict["video_height"] = 0
  417. return video_url_dict
  418. @classmethod
  419. def get_comment_cnt(cls, item_id):
  420. url = "https://www.ixigua.com/tlb/comment/article/v5/tab_comments/?"
  421. params = {
  422. "tab_index": "0",
  423. "count": "10",
  424. "offset": "10",
  425. "group_id": str(item_id),
  426. "item_id": str(item_id),
  427. "aid": "1768",
  428. "msToken": "50-JJObWB07HfHs-BMJWT1eIDX3G-6lPSF_i-QwxBIXE9VVa-iN0jbEXR5pG2DKjXBmP299n6ZTuXzY-GAy968CCvouSAYIS4GzvGQT3pNlKNejr5G4-1g==",
  429. "X-Bogus": "DFSzswVOyGtANVeWtCLMqR/F6q9U",
  430. "_signature": cls.random_signature(),
  431. }
  432. headers = {
  433. 'authority': 'www.ixigua.com',
  434. 'accept': 'application/json, text/plain, */*',
  435. 'accept-language': 'zh-CN,zh;q=0.9,en;q=0.8,en-GB;q=0.7,en-US;q=0.6',
  436. 'cache-control': 'no-cache',
  437. 'cookie': 'MONITOR_WEB_ID=67cb5099-a022-4ec3-bb8e-c4de6ba51dd0; passport_csrf_token=72b2574f3c99f8ba670e42df430218fd; passport_csrf_token_default=72b2574f3c99f8ba670e42df430218fd; sid_guard=c7472b508ea631823ba765a60cf8757f%7C1680867422%7C3024002%7CFri%2C+12-May-2023+11%3A37%3A04+GMT; uid_tt=c13f47d51767f616befe32fb3e9f485a; uid_tt_ss=c13f47d51767f616befe32fb3e9f485a; sid_tt=c7472b508ea631823ba765a60cf8757f; sessionid=c7472b508ea631823ba765a60cf8757f; sessionid_ss=c7472b508ea631823ba765a60cf8757f; sid_ucp_v1=1.0.0-KGUzNWYxNmRkZGJiZjgxY2MzZWNkMTEzMTkwYjY1Yjg5OTY5NzVlNmMKFQiu3d-eqQIQ3oDAoQYYGCAMOAhACxoCaGwiIGM3NDcyYjUwOGVhNjMxODIzYmE3NjVhNjBjZjg3NTdm; ssid_ucp_v1=1.0.0-KGUzNWYxNmRkZGJiZjgxY2MzZWNkMTEzMTkwYjY1Yjg5OTY5NzVlNmMKFQiu3d-eqQIQ3oDAoQYYGCAMOAhACxoCaGwiIGM3NDcyYjUwOGVhNjMxODIzYmE3NjVhNjBjZjg3NTdm; odin_tt=b893608d4dde2e1e8df8cd5d97a0e2fbeafc4ca762ac72ebef6e6c97e2ed19859bb01d46b4190ddd6dd17d7f9678e1de; SEARCH_CARD_MODE=7168304743566296612_0; support_webp=true; support_avif=false; csrf_session_id=a5355d954d3c63ed1ba35faada452b4d; tt_scid=7Pux7s634-z8DYvCM20y7KigwH5u7Rh6D9C-RROpnT.aGMEcz6Vsxp.oai47wJqa4f86; ttwid=1%7CHHtv2QqpSGuSu8r-zXF1QoWsvjmNi1SJrqOrZzg-UCY%7C1683858689%7Ca5223fe1500578e01e138a0d71d6444692018296c4c24f5885af174a65873c95; ixigua-a-s=3; msToken=50-JJObWB07HfHs-BMJWT1eIDX3G-6lPSF_i-QwxBIXE9VVa-iN0jbEXR5pG2DKjXBmP299n6ZTuXzY-GAy968CCvouSAYIS4GzvGQT3pNlKNejr5G4-1g==; __ac_nonce=0645dcbf0005064517440; __ac_signature=_02B4Z6wo00f01FEGmAwAAIDBKchzCGqn-MBRJpyAAHAjieFC5GEg6gGiwz.I4PRrJl7f0GcixFrExKmgt6QI1i1S-dQyofPEj2ugWTCnmKUdJQv-wYuDofeKNe8VtMtZq2aKewyUGeKU-5Ud21; ixigua-a-s=3',
  438. 'pragma': 'no-cache',
  439. 'referer': f'https://www.ixigua.com/{item_id}?logTag=3c5aa86a8600b9ab8540',
  440. 'sec-ch-ua': '"Microsoft Edge";v="113", "Chromium";v="113", "Not-A.Brand";v="24"',
  441. 'sec-ch-ua-mobile': '?0',
  442. 'sec-ch-ua-platform': '"macOS"',
  443. 'sec-fetch-dest': 'empty',
  444. 'sec-fetch-mode': 'cors',
  445. 'sec-fetch-site': 'same-origin',
  446. 'tt-anti-token': 'cBITBHvmYjEygzv-f9c78c1297722cf1f559c74b084e4525ce4900bdcf9e8588f20cc7c2e3234422',
  447. 'user-agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36 Edg/113.0.1774.35',
  448. 'x-secsdk-csrf-token': '000100000001f8e733cf37f0cd255a51aea9a81ff7bc0c09490cfe41ad827c3c5c18ec809279175e4d9f5553d8a5'
  449. }
  450. urllib3.disable_warnings()
  451. s = requests.session()
  452. # max_retries=3 重试3次
  453. s.mount('http://', HTTPAdapter(max_retries=3))
  454. s.mount('https://', HTTPAdapter(max_retries=3))
  455. response = s.get(url=url, headers=headers, params=params, verify=False, proxies=Common.tunnel_proxies(), timeout=5)
  456. response.close()
  457. if response.status_code != 200 or 'total_number' not in response.json() or response.json() == {}:
  458. return 0
  459. return response.json().get("total_number", 0)
  460. # 获取视频详情
  461. @classmethod
  462. def get_video_info(cls, log_type, crawler, item_id):
  463. url = 'https://www.ixigua.com/api/mixVideo/information?'
  464. headers = {
  465. "accept-encoding": "gzip, deflate",
  466. "accept-language": "zh-CN,zh-Hans;q=0.9",
  467. "user-agent": get_random_user_agent('pc'),
  468. "referer": "https://www.ixigua.com/7102614741050196520?logTag=0531c88ac04f38ab2c62",
  469. }
  470. params = {
  471. 'mixId': str(item_id),
  472. 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfC'
  473. 'NVVIOBNjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
  474. 'X-Bogus': 'DFSzswVupYTANCJOSBk0P53WxM-r',
  475. '_signature': '_02B4Z6wo0000119LvEwAAIDCuktNZ0y5wkdfS7jAALThuOR8D9yWNZ.EmWHKV0WSn6Px'
  476. 'fPsH9-BldyxVje0f49ryXgmn7Tzk-swEHNb15TiGqa6YF.cX0jW8Eds1TtJOIZyfc9s5emH7gdWN94',
  477. }
  478. cookies = {
  479. 'ixigua-a-s': '1',
  480. 'msToken': 'IlG0wd0Pylyw9ghcYiB2YseUmTwrsrqqhXrbIcsSaTcLTJyVlbYJzk20zw3UO-CfrfCNVVIOB'
  481. 'NjIl7vfBoxnVUwO9ZyzAI3umSKsT5-pef_RRfQCJwmA',
  482. 'ttwid': '1%7C_yXQeHWwLZgCsgHClOwTCdYSOt_MjdOkgnPIkpi-Sr8%7C1661241238%7Cf57d0c5ef3f1d7'
  483. '6e049fccdca1ac54887c34d1f8731c8e51a49780ff0ceab9f8',
  484. 'tt_scid': 'QZ4l8KXDG0YAEaMCSbADdcybdKbUfG4BC6S4OBv9lpRS5VyqYLX2bIR8CTeZeGHR9ee3',
  485. 'MONITOR_WEB_ID': '0a49204a-7af5-4e96-95f0-f4bafb7450ad',
  486. '__ac_nonce': '06304878000964fdad287',
  487. '__ac_signature': '_02B4Z6wo00f017Rcr3AAAIDCUVxeW1tOKEu0fKvAAI4cvoYzV-wBhq7B6D8k0no7lb'
  488. 'FlvYoinmtK6UXjRIYPXnahUlFTvmWVtb77jsMkKAXzAEsLE56m36RlvL7ky.M3Xn52r9t1IEb7IR3ke8',
  489. 'ttcid': 'e56fabf6e85d4adf9e4d91902496a0e882',
  490. '_tea_utm_cache_1300': 'undefined',
  491. 'support_avif': 'false',
  492. 'support_webp': 'false',
  493. 'xiguavideopcwebid': '7134967546256016900',
  494. 'xiguavideopcwebid.sig': 'xxRww5R1VEMJN_dQepHorEu_eAc',
  495. }
  496. urllib3.disable_warnings()
  497. s = requests.session()
  498. # max_retries=3 重试3次
  499. s.mount('http://', HTTPAdapter(max_retries=3))
  500. s.mount('https://', HTTPAdapter(max_retries=3))
  501. response = s.get(url=url, headers=headers, params=params, cookies=cookies, verify=False, proxies=Common.tunnel_proxies(), timeout=5)
  502. response.close()
  503. if response.status_code != 200 or 'data' not in response.json() or response.json()['data'] == {}:
  504. Log.logging(log_type, crawler).warning(f"get_video_info:{response.status_code}, {response.text}\n")
  505. return None
  506. else:
  507. video_info = response.json()['data'].get("gidInformation", {}).get("packerData", {}).get("video", {})
  508. if video_info == {}:
  509. return None
  510. video_dict = {
  511. "video_title": video_info.get("title", ""),
  512. "video_id": video_info.get("videoResource", {}).get("vid", ""),
  513. "gid": str(item_id),
  514. "play_cnt": int(video_info.get("video_watch_count", 0)),
  515. "like_cnt": int(video_info.get("video_like_count", 0)),
  516. "comment_cnt": int(cls.get_comment_cnt(item_id)),
  517. "share_cnt": 0,
  518. "favorite_cnt": 0,
  519. "duration": int(video_info.get("video_duration", 0)),
  520. "video_width": int(cls.get_video_url(video_info)["video_width"]),
  521. "video_height": int(cls.get_video_url(video_info)["video_height"]),
  522. "publish_time_stamp": int(video_info.get("video_publish_time", 0)),
  523. "publish_time_str": time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(video_info.get("video_publish_time", 0)))),
  524. "user_name": video_info.get("user_info", {}).get("name", ""),
  525. "user_id": str(video_info.get("user_info", {}).get("user_id", "")),
  526. "avatar_url": str(video_info.get("user_info", {}).get("avatar_url", "")),
  527. "cover_url": video_info.get("poster_url", ""),
  528. "audio_url": cls.get_video_url(video_info)["audio_url"],
  529. "video_url": cls.get_video_url(video_info)["video_url"],
  530. "session": f"xigua-search-{int(time.time())}"
  531. }
  532. return video_dict
  533. @classmethod
  534. def repeat_video(cls, log_type, crawler, video_id, env):
  535. # sql = f""" select * from crawler_video where platform="{cls.platform}" and out_video_id="{video_id}"; """
  536. sql = f""" select * from crawler_video where platform in ("{crawler}","{cls.platform}") and out_video_id="{video_id}"; """
  537. repeat_video = MysqlHelper.get_values(log_type, crawler, sql, env, action="")
  538. return len(repeat_video)
  539. # 下载 / 上传
  540. @classmethod
  541. def download_publish(cls, log_type, crawler, user_dict, video_dict, rule_dict, title_score, env):
  542. Common.download_method(log_type=log_type, crawler=crawler, text='xigua_video',
  543. title=video_dict['video_title'], url=video_dict['video_url'])
  544. # 下载音频
  545. Common.download_method(log_type=log_type, crawler=crawler, text='xigua_audio',
  546. title=video_dict['video_title'], url=video_dict['audio_url'])
  547. # 合成音视频
  548. Common.video_compose(log_type=log_type, crawler=crawler,
  549. video_dir=f"./{crawler}/videos/{video_dict['video_title']}")
  550. md_title = md5(video_dict['video_title'].encode('utf8')).hexdigest()
  551. try:
  552. if os.path.getsize(f"./{crawler}/videos/{md_title}/video.mp4") == 0:
  553. # 删除视频文件夹
  554. shutil.rmtree(f"./{crawler}/videos/{md_title}")
  555. Log.logging(log_type, crawler).info("视频size=0,删除成功\n")
  556. return
  557. except FileNotFoundError:
  558. # 删除视频文件夹
  559. shutil.rmtree(f"./{crawler}/videos/{md_title}")
  560. Log.logging(log_type, crawler).info("视频文件不存在,删除文件夹成功\n")
  561. return
  562. # 下载封面
  563. Common.download_method(log_type=log_type, crawler=crawler, text='cover',
  564. title=video_dict['video_title'], url=video_dict['cover_url'])
  565. # 保存视频信息至txt
  566. Common.save_video_info(log_type=log_type, crawler=crawler, video_dict=video_dict)
  567. # 上传视频
  568. Log.logging(log_type, crawler).info("开始上传视频...")
  569. if env == "dev":
  570. oss_endpoint = "out"
  571. our_video_id = Publish.upload_and_publish(log_type=log_type,
  572. crawler=crawler,
  573. strategy="搜索抓取策略",
  574. our_uid=user_dict["uid"],
  575. env=env,
  576. oss_endpoint=oss_endpoint)
  577. our_video_link = f"https://testadmin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  578. else:
  579. oss_endpoint = "inner"
  580. our_video_id = Publish.upload_and_publish(log_type=log_type,
  581. crawler=crawler,
  582. strategy="搜索抓取策略",
  583. our_uid=user_dict["uid"],
  584. env=env,
  585. oss_endpoint=oss_endpoint)
  586. our_video_link = f"https://admin.piaoquantv.com/cms/post-detail/{our_video_id}/info"
  587. if our_video_id is None:
  588. try:
  589. # 删除视频文件夹
  590. shutil.rmtree(f"./{crawler}/videos/{md_title}")
  591. return
  592. except FileNotFoundError:
  593. return
  594. # 视频信息保存数据库
  595. insert_sql = f""" insert into crawler_video(video_id,
  596. user_id,
  597. out_user_id,
  598. platform,
  599. strategy,
  600. out_video_id,
  601. video_title,
  602. cover_url,
  603. video_url,
  604. duration,
  605. publish_time,
  606. play_cnt,
  607. crawler_rule,
  608. width,
  609. height)
  610. values({our_video_id},
  611. {user_dict["uid"]},
  612. "{video_dict['user_id']}",
  613. "{cls.platform}",
  614. "搜索爬虫策略",
  615. "{video_dict['video_id']}",
  616. "{video_dict['video_title']}",
  617. "{video_dict['cover_url']}",
  618. "{video_dict['video_url']}",
  619. {int(video_dict['duration'])},
  620. "{video_dict['publish_time_str']}",
  621. {int(video_dict['play_cnt'])},
  622. '{json.dumps(rule_dict)}',
  623. {int(video_dict['video_width'])},
  624. {int(video_dict['video_height'])}) """
  625. Log.logging(log_type, crawler).info(f"insert_sql:{insert_sql}")
  626. MysqlHelper.update_values(log_type, crawler, insert_sql, env, action="")
  627. cls.download_cnt += 1
  628. Log.logging(log_type, crawler).info("视频信息写入数据库完成")
  629. # 视频信息写入飞书
  630. Feishu.insert_columns(log_type, crawler, "BUNvGC", "ROWS", 1, 2)
  631. values = [[title_score,
  632. user_dict["link"],
  633. time.strftime("%Y-%m-%d %H:%M:%S", time.localtime(int(time.time()))),
  634. "关键词搜索",
  635. video_dict['video_title'],
  636. str(video_dict['video_id']),
  637. our_video_link,
  638. video_dict['gid'],
  639. video_dict['play_cnt'],
  640. video_dict['comment_cnt'],
  641. video_dict['like_cnt'],
  642. video_dict['share_cnt'],
  643. video_dict['duration'],
  644. str(video_dict['video_width']) + '*' + str(video_dict['video_height']),
  645. video_dict['publish_time_str'],
  646. video_dict['user_name'],
  647. video_dict['user_id'],
  648. video_dict['avatar_url'],
  649. video_dict['cover_url'],
  650. video_dict['video_url'],
  651. video_dict['audio_url']]]
  652. time.sleep(0.5)
  653. Feishu.update_values(log_type, crawler, "BUNvGC", "D2:Z2", values)
  654. Log.logging(log_type, crawler).info('视频信息写入飞书完成\n')
  655. @classmethod
  656. def get_search_videos(cls, log_type, crawler, user_list, rule_dict, env):
  657. Log.logging(log_type, crawler).info(f"搜索词总数:{len(user_list)}\n")
  658. for user_dict in user_list:
  659. try:
  660. cls.download_cnt = 0
  661. Log.logging(log_type, crawler).info(f"开始抓取 {user_dict['link']} 视频")
  662. cls.get_videoList(log_type=log_type,
  663. crawler=crawler,
  664. user_dict=user_dict,
  665. rule_dict=rule_dict,
  666. env=env)
  667. except Exception as e:
  668. Log.logging(log_type, crawler).error(f"抓取{user_dict['link']}视频时异常:{e}\n")
  669. @classmethod
  670. def get_videoList(cls, log_type, crawler, user_dict, rule_dict, env):
  671. # mq = MQ(topic_name="topic_crawler_etl_" + env)
  672. # 打印请求配置
  673. ca = DesiredCapabilities.CHROME
  674. ca["goog:loggingPrefs"] = {"performance": "ALL"}
  675. # # 不打开浏览器运行
  676. chrome_options = webdriver.ChromeOptions()
  677. chrome_options.add_argument(f'user-agent=Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.79 Safari/537.36')
  678. chrome_options.add_argument("--headless")
  679. chrome_options.add_argument("--window-size=1920,1080")
  680. chrome_options.add_argument("--no-sandbox")
  681. if env == "dev":
  682. chromedriver = "/Users/wangkun/Downloads/chromedriver/chromedriver_v114/chromedriver"
  683. else:
  684. chromedriver = "/usr/bin/chromedriver"
  685. # driver初始化
  686. driver = webdriver.Chrome(desired_capabilities=ca, options=chrome_options, service=Service(chromedriver))
  687. driver.implicitly_wait(10)
  688. Log.logging(log_type, crawler).info(f"打开搜索页:{user_dict['link']}")
  689. driver.get(f"https://www.ixigua.com/search/{user_dict['link']}/")
  690. time.sleep(2)
  691. Log.logging(log_type, crawler).info("关闭登录弹框")
  692. if driver.find_elements(By.XPATH, '//*[@class="xg-notification-close"]') != 0:
  693. driver.find_element(By.XPATH, '//*[@class="xg-notification-close"]').click()
  694. # driver.get_screenshot_as_file(f"./{crawler}/photos/{user_dict['link']}-关闭登录弹框.png")
  695. Log.logging(log_type, crawler).info("展开筛选按钮")
  696. driver.find_element(By.XPATH, '//*[@class="searchPageV2__header-icons-categories"]').click()
  697. Log.logging(log_type, crawler).info("点击最新排序")
  698. driver.find_element(By.XPATH, '//*[@class="searchPageV2__header-categories-wrapper"]/*[1]/*[2]/*[1]').click()
  699. time.sleep(1)
  700. # driver.get_screenshot_as_file(f"./{crawler}/photos/{user_dict['link']}-最新排序.png")
  701. Log.logging(log_type, crawler).info("收起筛选按钮\n")
  702. driver.find_element(By.XPATH, '//*[@class="searchPageV2__header-icons-categories"]').click()
  703. index = 0
  704. num = 0
  705. while True:
  706. # video_elements = driver.find_elements(By.XPATH, '//*[@class="HorizontalFeedCard searchPageV2__card single"]')
  707. video_elements = driver.find_elements(By.XPATH, '//*[@class="HorizontalFeedCard searchPageV2__card"]')
  708. video_element_temp = video_elements[index:]
  709. if len(video_element_temp) == 0:
  710. Log.logging(log_type, crawler).info('到底啦~~~~~~~~~~~~~\n')
  711. driver.quit()
  712. return
  713. for i, video_element in enumerate(video_element_temp):
  714. try:
  715. if cls.download_cnt >= int(rule_dict.get("videos_cnt", {}).get("min", 30)):
  716. Log.logging(log_type, crawler).info(f"搜索词: {user_dict['link']},已下载视频数: {cls.download_cnt}\n")
  717. driver.quit()
  718. return
  719. if video_element is None:
  720. Log.logging(log_type, crawler).info('到底啦~\n')
  721. driver.quit()
  722. return
  723. driver.find_elements(By.XPATH, '//*[@class="HorizontalFeedCard searchPageV2__card"]')
  724. num += 1
  725. Log.logging(log_type, crawler).info(f'拖动"视频"列表第{num}个至屏幕中间')
  726. driver.execute_script("arguments[0].scrollIntoView({block:'center',inline:'center'})", video_element)
  727. time.sleep(1)
  728. # driver.get_screenshot_as_file(f"./{crawler}/photos/{user_dict['link']}-{num}.png")
  729. title = video_element.find_elements(By.XPATH, '//*[@class="HorizontalFeedCard__coverWrapper disableZoomAnimation"]')[index+i-1].get_attribute('title')
  730. publish_day = video_element.find_elements(By.XPATH, '//*[@class="HorizontalFeedCard-accessories-bottomInfo__statistics"]')[index+i-1].text.split('· ')[-1]
  731. Log.logging(log_type, crawler).info(f"标题:{title}")
  732. Log.logging(log_type, crawler).info(f"发布时间:{publish_day}")
  733. if "年" in publish_day:
  734. Log.logging(log_type, crawler).info("发布时间超过 1 年\n")
  735. driver.quit()
  736. return
  737. item_id = video_element.find_elements(By.XPATH, '//*[@class="HorizontalFeedCard__coverWrapper disableZoomAnimation"]')[index+i-1].get_attribute('href')
  738. item_id = item_id.split("com/")[-1].split("?&")[0]
  739. video_dict = cls.get_video_info(log_type, crawler, item_id)
  740. if video_dict is None:
  741. Log.logging(log_type, crawler).info("无效视频\n")
  742. continue
  743. for k, v in video_dict.items():
  744. Log.logging(log_type, crawler).info(f"{k}:{v}")
  745. # if int((int(time.time()) - int(video_dict["publish_time_stamp"])) / (3600 * 24)) > int(rule_dict.get("period", {}).get("max", 1000)):
  746. # Log.logging(log_type, crawler).info(f'发布时间超过{int(rule_dict.get("period", {}).get("max", 1000))}天\n')
  747. # driver.quit()
  748. # return
  749. if download_rule(log_type=log_type, crawler=crawler, video_dict=video_dict, rule_dict=rule_dict) is False:
  750. Log.logging(log_type, crawler).info("不满足抓取规则\n")
  751. elif any(str(word) if str(word) in video_dict["video_title"] else False
  752. for word in get_config_from_mysql(log_type=log_type,
  753. source=crawler,
  754. env=env,
  755. text="filter",
  756. action="")) is True:
  757. Log.logging(log_type, crawler).info('已中过滤词\n')
  758. elif cls.repeat_video(log_type, crawler, video_dict["video_id"], env) != 0:
  759. Log.logging(log_type, crawler).info('视频已下载\n')
  760. else:
  761. # title_score = get_title_score(log_type, "kuaishou", "16QspO", "0usaDk", video_dict["video_title"])
  762. # if title_score <= 0.3:
  763. # Log.logging(log_type, crawler).info(f"权重分:{title_score}<=0.3\n")
  764. # continue
  765. # Log.logging(log_type, crawler).info(f"权重分:{title_score}>0.3\n")
  766. # cls.download_publish(log_type=log_type,
  767. # crawler=crawler,
  768. # user_dict=user_dict,
  769. # video_dict=video_dict,
  770. # rule_dict=rule_dict,
  771. # title_score=title_score,
  772. # env=env)
  773. video_dict["out_user_id"] = video_dict["user_id"]
  774. video_dict["platform"] = crawler
  775. video_dict["strategy"] = log_type
  776. video_dict["out_video_id"] = video_dict["video_id"]
  777. video_dict["width"] = video_dict["video_width"]
  778. video_dict["height"] = video_dict["video_height"]
  779. video_dict["crawler_rule"] = json.dumps(rule_dict)
  780. video_dict["user_id"] = user_dict["uid"]
  781. video_dict["publish_time"] = video_dict["publish_time_str"]
  782. video_dict["strategy_type"] = log_type
  783. # mq.send_msg(video_dict)
  784. cls.download_cnt += 1
  785. Log.logging(log_type, crawler).info("已下载视频数+1\n")
  786. except Exception as e:
  787. Log.logging(log_type, crawler).warning(f"抓取单条视频异常:{e}\n")
  788. Log.logging(log_type, crawler).info('已抓取完一组视频,休眠10秒\n')
  789. time.sleep(10)
  790. index = index + len(video_element_temp)
  791. if __name__ == '__main__':
  792. pass