gpt4 book ai didi

python - 从 Instagram 中提取关注者数量

转载 作者:行者123 更新时间:2023-12-05 02:58:57 25 4
gpt4 key购买 nike

我正在尝试从 Instagram 帐户列表中提取关注者的数量。我曾尝试在 Requests 中使用“查找”方法,但是,当我从下面的代码中打印“r”时,我在检查实际 Instagram 时正在寻找的字符串不再出现。

找过去是能够得到这段代码运行成功,然而,将不再运行。 Webscraping Instagram follower count BeautifulSoup

import requests

user = "espn"
url = 'https://www.instagram.com/' + user
r = requests.get(url).text

start = '"edge_followed_by":{"count":'
end = '},"followed_by_viewer"'

print(r[r.find(start)+len(start):r.rfind(end)])

我收到一个“-1”错误,这意味着在变量“r”中找不到来自 find 方法的子字符串。

最佳答案

我认为这是因为最后一个“开始”和“第一个”结束......这会起作用:

import requests
import re

user = "espn"
url = 'https://www.instagram.com/' + user
r = requests.get(url).text
followers = re.search('"edge_followed_by":{"count":([0-9]+)}',r).group(1)

print(followers)

'14061730'

关于python - 从 Instagram 中提取关注者数量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58468678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com