|
@@ -31,10 +31,10 @@ def fxs_decrypt(ciphertext):
|
|
|
:param ciphertext: 秘文
|
|
|
:return: 原文
|
|
|
"""
|
|
|
- password = 'xlc2ze7qnqg8xi1d'.encode()
|
|
|
+ password = "xlc2ze7qnqg8xi1d".encode()
|
|
|
iv = password
|
|
|
try:
|
|
|
- ct = b64decode(ciphertext.encode('utf-8'))
|
|
|
+ ct = b64decode(ciphertext.encode("utf-8"))
|
|
|
cipher = AES.new(password, AES.MODE_CBC, iv)
|
|
|
pt = unpad(cipher.decrypt(ct), AES.block_size)
|
|
|
return pt.decode()
|
|
@@ -107,7 +107,7 @@ class FuXiaoShunRecommend(object):
|
|
|
data=mq_obj,
|
|
|
)
|
|
|
if self.download_cnt >= int(
|
|
|
- self.rule_dict.get("videos_cnt", {}).get("min", 200)
|
|
|
+ self.rule_dict.get("videos_cnt", {}).get("min", 200)
|
|
|
):
|
|
|
self.expire_flag = True
|
|
|
|
|
@@ -118,6 +118,12 @@ class FuXiaoShunRecommend(object):
|
|
|
:param page_index: 页码
|
|
|
:return: None
|
|
|
"""
|
|
|
+ if self.expire_flag:
|
|
|
+ self.aliyun_log.logging(
|
|
|
+ code="2000",
|
|
|
+ message="本轮已经抓取到足够的数据,自动退出\t{}".format(self.download_cnt),
|
|
|
+ )
|
|
|
+ return
|
|
|
headers = {
|
|
|
"Host": "shun.nnjuxing.cn",
|
|
|
"xweb_xhr": "1",
|
|
@@ -128,17 +134,16 @@ class FuXiaoShunRecommend(object):
|
|
|
"sec-fetch-mode": "cors",
|
|
|
"sec-fetch-dest": "empty",
|
|
|
"referer": "https://servicewechat.com/wx5b89401c90c9f367/3/page-frame.html",
|
|
|
- "accept-language": "en-US,en;q=0.9"
|
|
|
+ "accept-language": "en-US,en;q=0.9",
|
|
|
}
|
|
|
url = "https://shun.nnjuxing.cn/videos/api.videos/getItem"
|
|
|
- params = {
|
|
|
- "mark": "",
|
|
|
- "page": page_index
|
|
|
- }
|
|
|
- async with session.get(url, headers=headers, params=params, proxy=tunnel_proxies()['https']) as response:
|
|
|
+ params = {"mark": "", "page": page_index}
|
|
|
+ async with session.get(
|
|
|
+ url, headers=headers, params=params, proxy=tunnel_proxies()["https"]
|
|
|
+ ) as response:
|
|
|
cryp_data = await response.json()
|
|
|
- data = json.loads(fxs_decrypt(cryp_data['data']))
|
|
|
- for index, video_obj in enumerate(data['list'], 1):
|
|
|
+ data = json.loads(fxs_decrypt(cryp_data["data"]))
|
|
|
+ for index, video_obj in enumerate(data["list"], 1):
|
|
|
try:
|
|
|
self.aliyun_log.logging(
|
|
|
code="1001",
|
|
@@ -158,22 +163,28 @@ class FuXiaoShunRecommend(object):
|
|
|
:return: None
|
|
|
"""
|
|
|
async with aiohttp.ClientSession() as session:
|
|
|
- for page in range(1, 100):
|
|
|
- if self.expire_flag:
|
|
|
- self.aliyun_log.logging(
|
|
|
- code="2000",
|
|
|
- message="本轮已经抓取到足够的数据,自动退出\t{}".format(self.download_cnt)
|
|
|
- )
|
|
|
- message = "本轮已经抓取到足够的数据,自动退出\t{}".format(self.download_cnt)
|
|
|
- print(message)
|
|
|
- return
|
|
|
- else:
|
|
|
- try:
|
|
|
- await self.get_recommend_list(session, page_index=page)
|
|
|
- except Exception as e:
|
|
|
- self.aliyun_log.logging(
|
|
|
- code="3000",
|
|
|
- message="抓取第{}页时候出现错误, 报错信息是{}".format(page, e),
|
|
|
- )
|
|
|
-
|
|
|
-
|
|
|
+ tasks = [self.get_recommend_list(session, index) for index in range(1, 100)]
|
|
|
+ await asyncio.gather(*tasks)
|
|
|
+ done, pending = await asyncio.wait(
|
|
|
+ tasks, return_when=asyncio.FIRST_COMPLETED
|
|
|
+ )
|
|
|
+ # 取消所有剩余的任务
|
|
|
+ for task in pending:
|
|
|
+ task.cancel()
|
|
|
+ # for page in range(1, 100):
|
|
|
+ # if self.expire_flag:
|
|
|
+ # self.aliyun_log.logging(
|
|
|
+ # code="2000",
|
|
|
+ # message="本轮已经抓取到足够的数据,自动退出\t{}".format(self.download_cnt),
|
|
|
+ # )
|
|
|
+ # message = "本轮已经抓取到足够的数据,自动退出\t{}".format(self.download_cnt)
|
|
|
+ # print(message)
|
|
|
+ # return
|
|
|
+ # else:
|
|
|
+ # try:
|
|
|
+ # await self.get_recommend_list(session, page_index=page)
|
|
|
+ # except Exception as e:
|
|
|
+ # self.aliyun_log.logging(
|
|
|
+ # code="3000",
|
|
|
+ # message="抓取第{}页时候出现错误, 报错信息是{}".format(page, e),
|
|
|
+ # )
|