Python自动分页

2024-10-01 15:45:01 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试自动化我的脚本(在Python中),以便自动连续地获取end_光标。例如:

https://www.instagram.com/explore/tags/plebiscito/?__a=1

之后:

^{pr2}$

之后:

https://www.instagram.com/explore/tags/plebiscito/?__a=1&max_id=J0HWFB4fAAAAF0HWE2jPAAAAFkwA

。。。。 .... .... 在

这样做,直到最后一个结束光标结束。 如果你能帮我,我会很感激的,因为我不能。再次非常感谢。在

PD:我没有用API来做,因为沙盒不允许应用程序开发。在

更新:当输入链接时,End_cursor位于加载的所有内容中


Tags: https脚本comidwwwtagsexploremax
1条回答
网友
1楼 · 发布于 2024-10-01 15:45:01

因此,https://www.instagram.com/explore/tags/plebiscito/?__a=1返回一组以如下方式开头的JSON

{"tag": {"media": {"count": 18926, "page_info": {"has_previous_page": false, "start_cursor": "1404693250132394506", "end_cursor": "J0HWFCHOgAAAF0HWE8dgwAAAFiYA", "has_next_page": true}, "nodes": [{"code": "BN-eRGQh8IK", "dimensions": {"width": 750, "height": 538}, "comments_disabled": false, "owner": {"id": "311016089"}, "comments": {"count": 1}, "caption": "#plebiscito", "likes": {"count": 11}, "date": 1481672506, "thumbnail_src": "https://scontent.cdninstagram.com/t51.2885-15/s640x640/sh0.08/e35/c147.0.750.750/15338447_1774364399481982_8165079596765544448_n.jpg?...

解析JSON之后,可以获取end_cursor

^{pr2}$

然后检索下一个URL。在

我无法在手动操作的几秒钟内到达列表的末尾,因此我不知道最后一个end_cursor会发生什么。但我注意到了has_next_page键。也许是这样,那么:

data = json.loads(however_youre_getting_the_data('https://www.instagram.com/explore/tags/plebiscito/?__a=1'))
end_cursors = []
while data['tag']['media']['page_info']['has_next_page']:
    end_cursors.append(data['tag']['media']['page_info']['end_cursor'])
    data = json.loads(however_youre_getting_the_data('https://www.instagram.com/explore/tags/plebiscito/?__a=1&max_id={}'.format(end_cursors[-1])))

相关问题 更多 >

    热门问题