mirror of
https://github.com/suyiiyii/nonebot-bison.git
synced 2025-06-02 09:26:12 +08:00
✨ weibo 带 cookie mvp
This commit is contained in:
parent
7901b845ea
commit
4ce6b85f79
@ -13,6 +13,7 @@ from bs4 import BeautifulSoup as bs
|
||||
from ..post import Post
|
||||
from .platform import NewMessage
|
||||
from ..utils import Site, http_client
|
||||
from ..utils.site import create_cookie_client_manager
|
||||
from ..types import Tag, Target, RawPost, ApiError, Category
|
||||
|
||||
_HEADER = {
|
||||
@ -39,6 +40,7 @@ class WeiboSite(Site):
|
||||
name = "weibo.com"
|
||||
schedule_type = "interval"
|
||||
schedule_setting = {"seconds": 3}
|
||||
client_mgr = create_cookie_client_manager("weibo")
|
||||
|
||||
|
||||
class Weibo(NewMessage):
|
||||
@ -78,9 +80,11 @@ class Weibo(NewMessage):
|
||||
raise cls.ParseTargetException(prompt="正确格式:\n1. 用户数字UID\n2. https://weibo.com/u/xxxx")
|
||||
|
||||
async def get_sub_list(self, target: Target) -> list[RawPost]:
|
||||
client = await self.ctx.get_client()
|
||||
client = await self.ctx.get_client(target)
|
||||
header = {"Referer": f"https://m.weibo.cn/u/{target}", "MWeibo-Pwa": "1", "X-Requested-With": "XMLHttpRequest"}
|
||||
# 获取 cookie 见 https://docs.rsshub.app/zh/deploy/config#%E5%BE%AE%E5%8D%9A
|
||||
params = {"containerid": "107603" + target}
|
||||
res = await client.get("https://m.weibo.cn/api/container/getIndex?", params=params, timeout=4.0)
|
||||
res = await client.get("https://m.weibo.cn/api/container/getIndex?", headers=header, params=params, timeout=4.0)
|
||||
res_data = json.loads(res.text)
|
||||
if not res_data["ok"] and res_data["msg"] != "这里还没有内容":
|
||||
raise ApiError(res.request.url)
|
||||
|
@ -60,10 +60,10 @@ class CookieClientManager(ClientManager):
|
||||
return client
|
||||
|
||||
async def get_client_for_static(self) -> AsyncClient:
|
||||
pass
|
||||
return http_client()
|
||||
|
||||
async def get_query_name_client(self) -> AsyncClient:
|
||||
pass
|
||||
return http_client()
|
||||
|
||||
async def refresh_client(self):
|
||||
pass
|
||||
|
Loading…
x
Reference in New Issue
Block a user