Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] douyin关注用户列表接口翻页的问题 #210

Open
hp2577 opened this issue Dec 8, 2024 · 6 comments
Open

[QUESTION] douyin关注用户列表接口翻页的问题 #210

hp2577 opened this issue Dec 8, 2024 · 6 comments
Labels
已确认(confirmed) 该issue已被处理,将在下次推送中更新(The issue has been processed and will be updated in the next push) 提问(question) 想得到更多的详细支持(Further information is requested)

Comments

@hp2577
Copy link

hp2577 commented Dec 8, 2024

import asyncio
import json
from f2.log.logger import logger
from f2.apps.douyin.handler import DouyinHandler

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/follow",
    },
    "proxies": {"http://": None, "https://": None},
    "timeout": 1,
    "cookie":,
}

async def main():
    user_id = ""  # 公开关注的账号
    sec_user_id = ""  # 公开关注的账号
    # 隐私设置的账号
    # 至少提供user_id或sec_user_id中的一个参数
    # 根据max_time和min_time区间获取关注用户列表

    all_data = []
    async for following in DouyinHandler(kwargs).fetch_user_following(
        user_id=user_id,
        sec_user_id=sec_user_id,
        # max_time=1668606509,
        # min_time=0,
    ):
        if following.status_code!= 0:
            logger.error("错误代码:{0} 错误消息:{1}".format(
                following.status_code, following.status_msg))
        else:
            logger.info(
                " 用户昵称:{0} ".format(
                   following.nickname,
                )
            )
            all_data.append(following._to_list())

    with open('following.json', 'w') as f:
       json.dump(all_data, f)

if __name__ == "__main__":
    asyncio.run(main())  

出处:关注用户数据 🟢异步方法,用于获取指定用户关注的用户列表

logger.error_("错误代码:{0} 错误消息:{1}").format(
    following.status_code, following.status_msg)                 
# 此处AI报错,修改           
logger.error("错误代码:{0} 错误消息:{1}".format(
    following.status_code, following.status_msg))

"Referer": "https://www.douyin.com"   
 #修改    
"Referer": "https://www.douyin.com/follow"

我借助AI修改成了以上代码并获取了一个json,但是里面数组的排序不是我抖音的关注顺序(最近关注/最远关注),而是综合排序,所以这个问题该这么处理?
2

@hp2577 hp2577 added the 提问(question) 想得到更多的详细支持(Further information is requested) label Dec 8, 2024
@Johnserf-Seed
Copy link
Owner

传入source_type参数,4为综合,1为最近,3为最早,同时配合max_timemin_time定义时间区间

@Johnserf-Seed
Copy link
Owner

image

@hp2577
Copy link
Author

hp2577 commented Dec 10, 2024

感谢作者回复,我在引入source_type=1这个参数后不管是否指定max_time都会出现以下情况:
INFO 当前请求的offset:0
INFO 爬取了 1 个关注用户
INFO 等待 0 秒后继续
INFO 当前请求的offset:0
INFO 爬取了 1 个关注用户
INFO 等待 0 秒后继续
INFO 当前请求的offset:0
INFO 爬取了 1 个关注用户
一直循环并没有采集到任何信息

@Johnserf-Seed
Copy link
Owner

感谢作者回复,我在引入source_type=1这个参数后不管是否指定max_time都会出现以下情况: INFO 当前请求的offset:0 INFO 爬取了 1 个关注用户 INFO 等待 0 秒后继续 INFO 当前请求的offset:0 INFO 爬取了 1 个关注用户 INFO 等待 0 秒后继续 INFO 当前请求的offset:0 INFO 爬取了 1 个关注用户 一直循环并没有采集到任何信息

当时只处理了默认的 4 类型,现在修复了其他排序的参数问题
image

@Johnserf-Seed Johnserf-Seed added the 已确认(confirmed) 该issue已被处理,将在下次推送中更新(The issue has been processed and will be updated in the next push) label Dec 10, 2024
@Johnserf-Seed
Copy link
Owner

Johnserf-Seed commented Dec 10, 2024

修复代码已经推送,如果着急可以切换 v0.0.1.7-pw2分支拉取最新代码,注意方法的一些变动

@Johnserf-Seed Johnserf-Seed changed the title [QUESTION] [QUESTION] douyin关注用户列表接口翻页的问题 Dec 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
已确认(confirmed) 该issue已被处理,将在下次推送中更新(The issue has been processed and will be updated in the next push) 提问(question) 想得到更多的详细支持(Further information is requested)
Projects
None yet
Development

No branches or pull requests

2 participants