mirror of
https://github.com/rachelos/we-mp-rss.git
synced 2026-09-24 16:02:42 +08:00
1.4.8-优化获取内容间隔,降低被风控概率
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
import random
|
||||
import time
|
||||
from core.print import print_warning
|
||||
def Wait(min=10,max=60,tips:str=""):
|
||||
wait=random.randint(min,max)
|
||||
print_warning(f"{tips} 等待{wait}秒后重试...")
|
||||
time.sleep(wait)
|
||||
+4
-3
@@ -10,6 +10,7 @@ from core.print import print_error,print_info, print_warning
|
||||
from core.rss import RSS
|
||||
from driver.success import setStatus
|
||||
from driver.wxarticle import Web
|
||||
from core.wait import Wait
|
||||
import random
|
||||
# 定义一些常见的 User-Agent
|
||||
USER_AGENTS = [
|
||||
@@ -111,7 +112,7 @@ class WxGather:
|
||||
text = r.text
|
||||
text=self.remove_common_html_elements(text)
|
||||
if "当前环境异常,完成验证后即可继续访问" in text:
|
||||
self.Wait(tips="当前环境异常,完成验证后即可继续访问")
|
||||
Wait(tips="当前环境异常,完成验证后即可继续访问")
|
||||
text=""
|
||||
except:
|
||||
pass
|
||||
@@ -142,7 +143,7 @@ class WxGather:
|
||||
art["ext"]=Ext_Data
|
||||
# art.pop("content")
|
||||
self.articles.append(art)
|
||||
|
||||
Wait(min=1,max=5,tips=f"获取 {data['title']}...")
|
||||
|
||||
#通过公众号码平台接口查询公众号
|
||||
def search_Biz(self,kw:str="",limit=10,offset=0):
|
||||
@@ -207,7 +208,7 @@ class WxGather:
|
||||
_cookies.append({'name':'token','value':self.token})
|
||||
if CallBack is not None:
|
||||
CallBack(item)
|
||||
self.Wait(tips=f"{item['title']} 处理完成",min=3,max=10)
|
||||
self.Wait(tips=f"{item['mps_title']} 处理完成",min=3,max=10)
|
||||
pass
|
||||
def Error(self,error:str,code=None):
|
||||
self.Over()
|
||||
|
||||
+2
-5
@@ -4,6 +4,7 @@ from .playwright_driver import PlaywrightController
|
||||
from typing import Dict
|
||||
from core.print import print_error,print_info,print_success,print_warning
|
||||
import time
|
||||
import core.wait as Wait
|
||||
import base64
|
||||
import re
|
||||
import os
|
||||
@@ -202,7 +203,7 @@ class WXArticleFetcher:
|
||||
article_data['content'] = content_backup
|
||||
|
||||
# 避免请求过快,但只在非最后一个请求时等待
|
||||
self.Wait(3,10,tips=f"处理第 {i}/{total_count} 篇文章")
|
||||
Wait(1,2,tips=f"处理第 {i}/{total_count} 篇文章")
|
||||
|
||||
except Exception as e:
|
||||
print_error(f"处理文章失败 {url}: {e}")
|
||||
@@ -223,10 +224,6 @@ class WXArticleFetcher:
|
||||
with ThreadPoolExecutor() as pool:
|
||||
future = loop.run_in_executor(pool, self.get_article_content, url)
|
||||
return await future
|
||||
def Wait(self,min=10,max=60,tips:str=""):
|
||||
wait=random.randint(min,max)
|
||||
print_warning(f"{tips}等待{wait}秒后重试...")
|
||||
time.sleep(wait)
|
||||
def get_article_content(self, url: str) -> Dict:
|
||||
"""获取单篇文章详细内容
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from core.models.article import Article,DATA_STATUS
|
||||
import core.db as db
|
||||
from core.wait import Wait
|
||||
from core.wx.base import WxGather
|
||||
from time import sleep
|
||||
from core.print import print_success,print_error
|
||||
@@ -35,7 +36,6 @@ def fetch_articles_without_content():
|
||||
content=Web.get_article_content(url).get("content")
|
||||
else:
|
||||
content = ga.content_extract(url)
|
||||
sleep(random.randint(3,10))
|
||||
if content:
|
||||
# 更新内容
|
||||
article.content = content
|
||||
@@ -46,7 +46,7 @@ def fetch_articles_without_content():
|
||||
print_success(f"成功更新文章 {article.title} 的内容")
|
||||
else:
|
||||
print_error(f"获取文章 {article.title} 内容失败")
|
||||
|
||||
Wait(min=5,max=10,tips=f"修正 {article.title}... 完成")
|
||||
except Exception as e:
|
||||
print(f"处理过程中发生错误: {e}")
|
||||
finally:
|
||||
|
||||
Reference in New Issue
Block a user