Skip to content

开发者必看

如果你是开发者或贡献着,开发前请阅读此文档再查看接口。

指定配置文件

开发者可以直接定义自己的配置文件,然后在测试时通过-c参数指定配置文件的路径,例如:

bash
f2 dy -c conf/app.yaml

也可以在代码中指定配置文件的路径,例如:

py
import f2

f2.APP_CONFIG_FILE_PATH = "app.yaml"

设置调试日志级别

py
import asyncio
from f2.apps.douyin.handler import DouyinHandler

from f2.log.logger import logger    
logger.setLevel("WARNING")    

kwargs = {
    "headers": {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0",
        "Referer": "https://www.douyin.com/",
    },
    "proxies": {"http://": None, "https://": None},
    "cookie": "YOUR_COOKIE_HERE",
}

if __name__ == "__main__":
    asyncio.run(DouyinHandler(kwargs).fetch_user_post(
        "MS4wLjABAAAA35iXl5qqCbLKY99pUvxkXzvpSXi8jgUbJ0zR4EuTpcHcS8PHaEb6G9yB6iKR0dNl"
        )
    )

支持代码接口模式的同时也支持在CLI模式中加上-d来指定记录日志级别。可选的参数DEBUGINFOWARNINGERROR

py
f2 -d WARNING -M post -u https://www.douyin.com/user/MS4wLjABAAAA35iXl5qqCbLKY99pUvxkXzvpSXi8jgUbJ0zR4EuTpcHcS8PHaEb6G9yB6iKR0dNl

set-debug

日志输出到控制台

py
import asyncio
from f2.apps.douyin.handler import DouyinHandler

from f2.log.logger import log_setup    
logger = log_setup(log_to_console=True)    

kwargs = {
    "headers": {
        "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/126.0.0.0 Safari/537.36 Edg/126.0.0.0",
        "Referer": "https://www.douyin.com/",
    },
    "proxies": {"http://": None, "https://": None},
    "cookie": "YOUR_COOKIE_HERE",
}

if __name__ == "__main__":
    asyncio.run(DouyinHandler(kwargs).fetch_user_post(
        "MS4wLjABAAAA35iXl5qqCbLKY99pUvxkXzvpSXi8jgUbJ0zR4EuTpcHcS8PHaEb6G9yB6iKR0dNl"
        )
    )

log-2-console

提示

如果你想要输出到控制台的日志更加详细,可以使用 DEBUG 级别。并且后续必须使用该logger对象来输出日志,否则日志将不会输出到控制台。

Released under the Apache-2.0 license.