API List
Note
🟢 Indicates implemented, 🟡 Indicates in progress or being modified, 🟤 Indicates temporarily not implemented, 🔵 Indicates possible future implementation, 🔴 Indicates deprecation.
handler API List
CLI Interface | Method |
---|---|
Download a Single Weibo | handle_one_weibo |
Download User's Weibo | handle_user_weibo |
Data Methods API | Method | Developer API |
---|---|---|
Create User Record & Directory | get_or_add_user_data | 🟢 |
Get User Info (UID) | fetch_user_info | 🟢 |
Get User Info (Screen Name) | fetch_user_info_by_screen_name | 🟢 |
Get User Details | fetch_user_detail | 🟢 |
Extract Weibo User ID | extract_weibo_uid | 🟢 |
Fetch Single Weibo Data | fetch_one_weibo | 🟢 |
Fetch User Weibo Data | fetch_user_weibo | 🟢 |
utils API List
Utility API | Class Name | Method | Status |
---|---|---|---|
Manage Client Config | ClientConfManager | 🟢 | |
Generate Visitor Cookie | VisitorManager | gen_visitor | 🟢 |
Extract Weibo ID | WeiboIdFetcher | get_weibo_id | 🟢 |
Extract All Weibo IDs | WeiboIdFetcher | get_all_weibo_id | 🟢 |
Extract Weibo User ID | WeiboUidFetcher | get_weibo_uid | 🟢 |
Extract All Weibo User IDs | WeiboUidFetcher | get_all_weibo_uid | 🟢 |
Extract Weibo User Screen Name | WeiboScreenNameFetcher | get_weibo_screen_name | 🟢 |
Extract All Weibo User Screen Names | WeiboScreenNameFetcher | get_all_weibo_screen_name | 🟢 |
Global File Name Formatter | - | format_file_name | 🟢 |
Create User Directory | - | create_user_folder | 🟢 |
Rename User Directory | - | rename_user_folder | 🟢 |
Create or Rename User Directory | - | create_or_rename_user_folder | 🟢 |
Extract Weibo Content | - | extract_desc | 🟢 |
crawler API List
Crawler URL API | Class Name | Method | Status |
---|---|---|---|
User Info API | WeiboCrawler | fetch_user_info | 🟢 |
User Details API | WeiboCrawler | fetch_user_detail | 🟢 |
User Weibo API | WeiboCrawler | fetch_user_weibo | 🟢 |
Single Weibo API | WeiboCrawler | fetch_weibo_detail | 🟢 |
dl API List
Downloader API | Class Name | Method | Status |
---|---|---|---|
Create Download Task | WeiboDownloader | create_download_task | 🟢 |
Handle Download Task | WeiboDownloader | handler_download | 🟢 |
Download Content | WeiboDownloader | download_desc | 🟢 |
Download Video | WeiboDownloader | download_video | 🟢 |
Download Image Gallery | WeiboDownloader | download_images | 🟢 |
💡 Tips
- Pagination parameters are included in the previous request data and can be conveniently filtered using the built-in
filter
function. - All APIs with pagination use asynchronous generator methods, requiring
async for
iteration for automatic pagination handling. - When
max_counts
is set toNone
or omitted, all available Weibo data will be fetched. - Easily integrates with backend frameworks such as
FastAPI
,Flask
, andDjango
. - Using a logged-in
cookie
can bypass privacy settings of the account.
handler API List
Create User Record & Directory 🟢
Asynchronous method to retrieve or create user data while also generating a user directory.
Parameter | Type | Description |
---|---|---|
kwargs | dict | CLI dictionary data, requires path parameter |
user_id | str | User ID |
db | AsyncUserDB | User database |
Returns | Type | Description |
---|---|---|
user_path | Path | User directory path object |
import asyncio
from f2.apps.weibo.handler import WeiboHandler
from f2.apps.weibo.db import AsyncUserDB
from f2.log.logger import logger
kwargs = {
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
"Referer": "https://www.weibo.com/",
},
"proxies": {"http://": None, "https://": None},
"cookie": "YOUR_COOKIE_HERE",
"path": "Download",
# "mode": "post",
}
async def main():
async with AsyncUserDB("weibo_users.db") as audb:
uid = "6524978930"
logger.info(
await WeiboHandler(kwargs).get_or_add_user_data(
kwargs=kwargs, uid=uid, db=audb
)
)
if __name__ == "__main__":
asyncio.run(main())
💡 Tips
- This is a
CLI
mode interface, developers can define their own user directory creation functionality. - If
mode
is not set, it defaults to thePLEASE_SETUP_MODE
directory.
Fetch User Info (UID) 🟢
Asynchronous method to retrieve user information by UID.
Parameter | Type | Description |
---|---|---|
uid | str | User ID |
Returns | Type | Description |
---|---|---|
UserInfoFilter | JsonModel | User information filter containing _to_raw , _to_dict methods |
import asyncio
from f2.apps.weibo.handler import WeiboHandler
from f2.log.logger import logger
kwargs = {
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
"Referer": "https://www.weibo.com/",
},
"proxies": {"http://": None, "https://": None},
"cookie": "YOUR_COOKIE_HERE",
}
async def main():
user = await WeiboHandler(kwargs).fetch_user_info(uid="2265830070")
# logger.info(
# f"微博用户ID: {user.uid}, 昵称: {user.nickname}, 性别: {user.gender}, 地区: {user.location}, 关注数: {user.friends_count}, 粉丝数: {user.followers_count}, 微博数: {user.weibo_count}, 个人主页: {user.profile_url}"
# )
logger.info("=================_to_raw================")
logger.info(user._to_raw())
# logger.info("=================_to_dict===============")
# logger.info(user._to_dict())
if __name__ == "__main__":
asyncio.run(main())
Fetch User Info (Screen Name) 🟢
Asynchronous method to retrieve user information by screen name.
Parameter | Type | Description |
---|---|---|
screen_name | str | User screen name |
Returns | Type | Description |
---|---|---|
UserInfoFilter | JsonModel | User information filter containing _to_raw , _to_dict methods |
import asyncio
from f2.apps.weibo.handler import WeiboHandler
from f2.log.logger import logger
kwargs = {
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
"Referer": "https://www.weibo.com/",
},
"proxies": {"http://": None, "https://": None},
"cookie": "YOUR_COOKIE_HERE",
}
async def main():
user = await WeiboHandler(kwargs).fetch_user_info_by_screen_name(
screen_name="阿里多多酱"
)
# logger.info(
# f"微博用户ID: {user.uid}, 昵称: {user.nickname}, 性别: {user.gender}, 地区: {user.location}, 关注数: {user.friends_count}, 粉丝数: {user.followers_count}, 微博数: {user.weibo_count}, 个人主页: {user.profile_url}"
# )
logger.info("=================_to_raw================")
logger.info(user._to_raw())
# logger.info("=================_to_dict===============")
# logger.info(user._to_dict())
if __name__ == "__main__":
asyncio.run(main())
Fetch User Details 🟢
Asynchronous method to retrieve detailed user information.
Parameter | Type | Description |
---|---|---|
uid | str | User ID |
Returns | Type | Description |
---|---|---|
UserDetailFilter | JsonModel | User detail filter containing _to_raw , _to_dict methods |
import asyncio
from f2.apps.weibo.handler import WeiboHandler
from f2.log.logger import logger
kwargs = {
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
"Referer": "https://www.weibo.com/",
},
"proxies": {"http://": None, "https://": None},
"cookie": "YOUR_COOKIE_HERE",
}
async def main():
user = await WeiboHandler(kwargs).fetch_user_detail(uid="2265830070")
# logger.info(
# f"用户ID: {uid}, 生日: {user.birthday}, 性别: {user.gender}, 地区: {user.location}, 个性签名: {user.description_raw}, 注册时间: {user.create_at}, 视频播放次数: {user.video_play_count}"
# )
logger.info("=================_to_raw================")
logger.info(user._to_raw())
# logger.info("=================_to_dict===============")
# logger.info(user._to_dict())
if __name__ == "__main__":
asyncio.run(main())
Extract Weibo User ID 🟢
Asynchronous method to extract and return user ID from a Weibo link.
Parameter | Type | Description |
---|---|---|
url | str | Weibo link |
Returns | Type | Description |
---|---|---|
uid | str | User ID |
import asyncio
from f2.apps.weibo.handler import WeiboHandler
from f2.log.logger import logger
kwargs = {
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
"Referer": "https://www.weibo.com/",
},
"proxies": {"http://": None, "https://": None},
}
async def main():
uid = await WeiboHandler(kwargs).extract_weibo_uid(
url="https://weibo.com/u/2265830070"
)
logger.info(f"微博用户ID: {uid}")
if __name__ == "__main__":
asyncio.run(main())
Fetch Single Weibo Data 🟢
Asynchronous method to retrieve a single Weibo post's data.
Parameter | Type | Description |
---|---|---|
weibo_id | str | Weibo ID |
Returns | Type | Description |
---|---|---|
WeiboDetailFilter | JsonModel | Weibo detail filter containing _to_raw , _to_dict methods |
import asyncio
from f2.apps.weibo.handler import WeiboHandler
from f2.log.logger import logger
kwargs = {
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
"Referer": "https://www.weibo.com/",
},
"proxies": {"http://": None, "https://": None},
"cookie": "YOUR_COOKIE_HERE",
}
async def main():
weibo = await WeiboHandler(kwargs).fetch_one_weibo(weibo_id="O8DM0BLLm")
# logger.info(
# f"微博ID: {weibo.weibo_id}, 微博文案: {weibo.desc}, 作者昵称: {weibo.nickname}, 发布时间: {weibo.weibo_created_at}"
# )
logger.info("=================_to_raw================")
logger.info(weibo._to_raw())
# logger.info("=================_to_dict===============")
# logger.info(weibo._to_dict())
if __name__ == "__main__":
asyncio.run(main())
Fetch User Weibo Data 🟢
Asynchronous method to retrieve a user's Weibo posts.
Parameter | Type | Description |
---|---|---|
uid | str | User ID |
page | int | Page number |
feature | int | Weibo type |
since_id | str | Starting Weibo ID |
max_counts | int | Maximum number of Weibo posts |
Returns | Type | Description |
---|---|---|
UserWeiboFilter | JsonModel | User Weibo filter containing _to_raw , _to_dict methods |
import asyncio
from f2.apps.weibo.handler import WeiboHandler
from f2.log.logger import logger
kwargs = {
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
"Referer": "https://www.weibo.com/",
},
"proxies": {"http://": None, "https://": None},
"cookie": "YOUR_COOKIE_HERE",
}
async def main():
async for weibo_list in WeiboHandler(kwargs).fetch_user_weibo(
uid="2265830070",
page=1,
feature=1,
since_id="",
max_counts=20,
):
# logger.info(
# f"微博ID: {weibo_list.weibo_id}, 微博文案: {weibo_list.weibo_desc_raw}, 作者昵称: {weibo_list.weibo_user_name_raw}, 发布时间: {weibo_list.weibo_created_at}"
# )
logger.info("=================_to_raw================")
logger.info(weibo_list._to_raw())
# logger.info("=================_to_dict===============")
# logger.info(weibo_list._to_dict())
# logger.info("=================_to_list===============")
# logger.info(weibo_list._to_list())
if __name__ == "__main__":
asyncio.run(main())
utils API List
Manage Client Configuration 🟢
Class method for managing client configuration.
Parameter | Type | Description |
---|---|---|
None | None | None |
Return | Type | Description |
---|---|---|
Config Value | Any | Configuration file value |
from f2.apps.weibo.utils import ClientConfManager
if __name__ == "__main__":
print("Client Configuration:")
print(ClientConfManager.client())
print("Client Configuration version:")
print(ClientConfManager.conf_version())
print("Client Configuration user-agent:")
print(ClientConfManager.user_agent())
Generate Visitor Cookie 🟢
Class method for generating a visitor cookie.
Parameter | Type | Description |
---|---|---|
None | None | None |
Return | Type | Description |
---|---|---|
visitor_cookie | str | Visitor Cookie |
import asyncio
from f2.apps.weibo.utils import VisitorManager
from f2.log.logger import logger
async def main():
visitor_cookie = await VisitorManager.gen_visitor()
logger.info(f"visitor_cookie: {visitor_cookie}")
if __name__ == "__main__":
asyncio.run(main())
Extract Weibo ID 🟢
Class method to extract a Weibo ID from a Weibo URL.
Parameter | Type | Description |
---|---|---|
url | str | Weibo link |
Return | Type | Description |
---|---|---|
weibo_id | str | Weibo ID |
import asyncio
from f2.apps.weibo.utils import WeiboIdFetcher
from f2.log.logger import logger
async def main():
raw_url = "https://weibo.com/2265830070/O8DM0BLLm"
return await WeiboIdFetcher.get_weibo_id(raw_url)
if __name__ == "__main__":
logger.info(asyncio.run(main()))
Extract Multiple Weibo IDs 🟢
Class method to extract multiple Weibo IDs from a list of Weibo URLs.
Parameter | Type | Description |
---|---|---|
urls | List[str] | List of Weibo links |
Return | Type | Description |
---|---|---|
weibo_ids | List[str] | List of Weibo IDs |
import asyncio
from f2.apps.weibo.utils import WeiboIdFetcher
from f2.utils.utils import extract_valid_urls
from f2.log.logger import logger
async def main():
raw_urls = [
"https://weibo.com/2265830070/O8DM0BLLm",
"https://weibo.com/2265830070/O8DM0BLLm/",
"https://weibo.com/2265830070/O8DM0BLLm/aasfasg",
"https://weibo.com/2265830070/O8DM0BLLm/?test=123",
"https://weibo.cn/2265830070/O8DM0BLLm/",
"https://weibo.cn/status/5020595169001740/?test=123",
"https://www.weibo.com/2265830070/5020595169001740",
]
# 提取有效URL
urls = extract_valid_urls(raw_urls)
# 对于URL列表
return await WeiboIdFetcher.get_all_weibo_id(urls)
if __name__ == "__main__":
logger.info(asyncio.run(main()))
Extract Weibo User ID 🟢
Class method to extract a Weibo user ID from a Weibo profile URL.
Parameter | Type | Description |
---|---|---|
url | str | Weibo profile link |
Return | Type | Description |
---|---|---|
uid | str | User ID |
import asyncio
from f2.apps.weibo.utils import WeiboUidFetcher
from f2.log.logger import logger
async def main():
raw_url = "https://weibo.com/u/2265830070"
return await WeiboUidFetcher.get_weibo_uid(raw_url)
if __name__ == "__main__":
logger.info(asyncio.run(main()))
❕ Tip
- The
extract_weibo_uid
method in the data interface can more comprehensively process Weibo URLs. However, this method is only applicable for non-nickname-based URLs.
Extract Multiple Weibo User IDs 🟢
Class method to extract multiple Weibo user IDs from a list of Weibo profile URLs.
Parameter | Type | Description |
---|---|---|
urls | List[str] | List of Weibo profile links |
Return | Type | Description |
---|---|---|
uids | List[str] | List of User IDs |
import asyncio
from f2.apps.weibo.utils import WeiboUidFetcher
from f2.utils.utils import extract_valid_urls
from f2.log.logger import logger
async def main():
raw_urls = [
"https://weibo.com/u/2265830070",
"https://weibo.com/u/2265830070/",
"https://weibo.com/u/2265830070/?test=123",
"https://weibo.com/2265830070",
"https://weibo.com/2265830070/",
"https://weibo.com/2265830070/?test=123",
"https://weibo.com/2265830070/O8DM0BLLm",
"https://weibo.com/2265830070/O8DM0BLLm/",
"https://weibo.com/2265830070/O8DM0BLLm/?test=123",
"https://weibo.com/2265830070/O8DM0BLLm/%$#",
"https://weibo.com/2265830070/O8DM0BLLm/" + "a" * 2048,
"https://m.weibo.cn/2265830070/5020595169001740",
"https://m.weibo.cn/2265830070/5020595169001740?test=123",
"https://m.weibo.cn/2265830070/5020595169001740/",
"https://m.weibo.cn/2265830070/5020595169001740/?test=123",
]
# 提取有效URL
urls = extract_valid_urls(raw_urls)
# 对于URL列表
return await WeiboUidFetcher.get_all_weibo_uid(urls)
if __name__ == "__main__":
logger.info(asyncio.run(main()))
Extract Weibo Username 🟢
Class method to extract a Weibo username from a Weibo profile URL.
Parameter | Type | Description |
---|---|---|
url | str | Weibo profile link |
Return | Type | Description |
---|---|---|
screen_name | str | Username |
import asyncio
from f2.apps.weibo.utils import WeiboScreenNameFetcher
from f2.log.logger import logger
async def main():
raw_url = "https://weibo.com/n/自我充电功能丧失"
return await WeiboScreenNameFetcher.get_weibo_screen_name(raw_url)
if __name__ == "__main__":
logger.info(asyncio.run(main()))
Extract Multiple Weibo Usernames 🟢
Class method to extract multiple Weibo usernames from a list of Weibo profile URLs.
Parameter | Type | Description |
---|---|---|
urls | List[str] | List of Weibo profile links |
Return | Type | Description |
---|---|---|
screen_names | List[str] | List of Usernames |
import asyncio
from f2.apps.weibo.utils import WeiboScreenNameFetcher
from f2.utils.utils import extract_valid_urls
from f2.log.logger import logger
async def main():
raw_urls = [
"https://weibo.com/n/%E8%87%AA%E6%88%91%E5%85%85%E7%94%B5%E5%8A%9F%E8%83%BD%E4%B8%A7%E5%A4%B1",
"https://weibo.com/n/%E8%87%AA%E6%88%91%E5%85%85%E7%94%B5%E5%8A%9F%E8%83%BD%E4%B8%A7%E5%A4%B1/",
"https://weibo.com/n/%E8%87%AA%E6%88%91%E5%85%85%E7%94%B5%E5%8A%9F%E8%83%BD%E4%B8%A7%E5%A4%B1?test=123",
"https://weibo.com/n/%E8%87%AA%E6%88%91%E5%85%85%E7%94%B5%E5%8A%9F%E8%83%BD%E4%B8%A7%E5%A4%B1/?test=123",
"https://weibo.com/n/自我充电功能丧失",
"https://weibo.com/n/自我充电功能丧失/",
"https://weibo.com/n/自我充电功能丧失?test=123",
"https://weibo.com/n/自我充电功能丧失/?test=123",
]
# 提取有效URL
urls = extract_valid_urls(raw_urls)
# 对于URL列表
return await WeiboScreenNameFetcher.get_all_weibo_screen_name(urls)
if __name__ == "__main__":
logger.info(asyncio.run(main()))
ℹ️ Tip
F2
automatically handles encoding, so you don't have to worry about escaping Chinese characters.
Global File Name Formatting 🟢
Formats filenames globally based on the configuration file.
📄 Filename Formatting Rules
Windows
filename length limit:255
characters; with long filename support, up to32,767
characters.Unix
filename length limit:255
characters.- Extracts
20
characters from the cleaned name and appends the suffix, ensuring it generally does not exceed255
characters. - Developers can define custom fields in
custom_fields
to generate custom filenames.
Parameter | Type | Description |
---|---|---|
naming_template | str | File naming template |
weibo_data | dict | Dictionary of Weibo post data |
custom_fields | dict | User-defined fields for replacing default values |
Return | Type | Description |
---|---|---|
file_name | str | Formatted file name |
import asyncio
from f2.apps.weibo.handler import WeiboHandler
from f2.apps.weibo.utils import format_file_name
async def main():
# 文件名模板
kwargs = {
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
"Referer": "https://www.weibo.com/",
},
"naming": "{create}_{desc}_{weibo_id}",
"cookie": "YOUR_COOKIE_HERE",
}
# 单作品的数据
weibo_data = await WeiboHandler(kwargs).fetch_one_weibo(weibo_id="LvFY288c0")
# 格式化后的文件名
print(format_file_name(kwargs.get("naming"), weibo_data._to_dict()) + "_weibo")
# 文件名模板
kwargs = {
# ...
"naming": "{create}_{desc}_{weibo_id}_{location}",
# ...
}
# 用户自定义字段
custom_fields = {"location": "Guang dong"}
# 格式化后的自定义文件名
print(
format_file_name(kwargs.get("naming"), weibo_data._to_dict(), custom_fields)
+ "_weibo"
)
if __name__ == "__main__":
asyncio.run(main())
Create User Directory 🟢
Creates a user directory if it does not already exist.
📂 User Directory Structure
If no path is specified in the configuration file, the default directory is Download
. Both absolute and relative paths are supported.
├── Download
│ ├── weibo
│ │ ├── post
│ │ │ ├── user_nickname
│ │ │ │ ├── 2023-12-31_23-59-59_desc
│ │ │ │ │ ├── 2023-12-31_23-59-59_desc-video.mp4
│ │ │ │ │ ├── 2023-12-31_23-59-59_desc-desc.txt
│ │ │ │ │ └── 2023-12-31_23-59-59_desc-cover.jpg
│ │ │ │ │ └── ......
│ │ ├── like
│ │ ├── ...
Parameter | Type | Description |
---|---|---|
kwargs | dict | CLI configuration file |
nickname | Union[str, int] | User nickname |
Return | Type | Description |
---|---|---|
user_path | Path | User directory path object |
from f2.apps.weibo.utils import create_user_folder
kwargs = {
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
"Referer": "https://www.weibo.com/",
},
"proxies": {"http": None, "https": None},
"cookie": "YOUR_COOKIE_HERE",
"path": "Download",
"mode": "post",
}
if __name__ == "__main__":
current_nickname = "New Nickname"
print(create_user_folder(kwargs, current_nickname))
# X:\......\Download\weibo\post\New Nickname
Rename User Directory 🟢
Used to rename a user directory.
Parameter | Type | Description |
---|---|---|
old_path | Path | Old user directory path object |
new_nickname | str | New user nickname |
Return | Type | Description |
---|---|---|
new_path | Path | New user directory path object |
import asyncio
from f2.apps.weibo.db import AsyncUserDB
from f2.apps.weibo.utils import rename_user_folder
from f2.apps.weibo.handler import WeiboHandler
kwargs = {
"headers": {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36 Edg/130.0.0.0",
"Referer": "https://www.weibo.com/",
},
"proxies": {"http://": None, "https://": None},
"cookie": "YOUR_COOKIE_HERE",
"path": "Download",
"mode": "post",
}
async def main():
uid = "2265830070"
async with AsyncUserDB("weibo_users.db") as audb:
local_user_path = await WeiboHandler(kwargs).get_or_add_user_data(
kwargs, uid, audb
)
print(local_user_path)
# X:\......\Download\weibo\post\阿里多多酱
current_nickname = "New Nickname"
new_user_path = rename_user_folder(local_user_path, current_nickname)
print(new_user_path)
# X:\......\Download\weibo\post\New Nickname
if __name__ == "__main__":
asyncio.run(main())
💡 Tip
If the directory does not exist, it will first create the user directory before renaming it.
Create or Rename User Directory 🟢
Used to create or rename a user directory. It combines the two interfaces above.
Parameter | Type | Description |
---|---|---|
kwargs | dict | CLI configuration file |
local_user_data | dict | Local user data |
current_nickname | str | Current user nickname |
Return | Type | Description |
---|---|---|
user_path | Path | User directory path object |
ℹ️ Tip
This interface effectively solves the problem of duplicate directory creation when users rename themselves. It is integrated into the handler
interface. Developers do not need to worry about it; they can directly call the data interface of handler
.
Extract Weibo Text 🟢
Used to extract Weibo text while excluding the final link.
Parameter | Type | Description |
---|---|---|
text | str | Weibo text |
Return | Type | Description |
---|---|---|
text | str | Extracted Weibo text |
from f2.apps.weibo.utils import extract_desc
from f2.log.logger import logger
def main():
raw_desc = {
"超大颗花生汤圆[舔屏] http://t.cn/A6nqzsFe",
"分享视频 http://t.cn/A6nNyQyS ",
"香宝宝 http://t.cn/A6mwArY7 ",
" 总有人类想要变成小猫咪^⌯𖥦⌯^ ੭ http://t.cn/A6n1zhGt ",
"过来挨踢[亲亲] http://t.cn/A6ndh6PS ",
"单独的文案 ", # 没有链接的情况
"http://t.cn/A6nqzsFe", # 只有链接的情况
" ", # 空字符串或空白内容
}
for text_raw in raw_desc:
desc = extract_desc(text_raw)
logger.info(f"提取结果: {desc}")
if __name__ == "__main__":
main()
Crawler API List
User Information API 🟢
Used to retrieve user information.
Parameter | Type | Description |
---|---|---|
params | UserInfo | User information API model |
Return | Type | Description |
---|---|---|
_fetch_get_json | dict | User information data |
User Details API 🟢
Used to retrieve user details.
Parameter | Type | Description |
---|---|---|
params | UserDetail | User details API model |
Return | Type | Description |
---|---|---|
_fetch_get_json | dict | User details data |
User Weibo API 🟢
Used to retrieve a user's Weibo posts.
Parameter | Type | Description |
---|---|---|
params | UserWeibo | User Weibo API model |
Return | Type | Description |
---|---|---|
_fetch_get_json | dict | User Weibo data |
Single Weibo API 🟢
Used to retrieve a single Weibo post.
Parameter | Type | Description |
---|---|---|
params | WeiboDetail | Single Weibo API model |
Return | Type | Description |
---|---|---|
_fetch_get_json | dict | Single Weibo data |