python - 获取 Instagram 关注者

标签 python beautifulsoup instagram screen-scraping

我想用 BeautifulSoup 解析网站的关注者数量。这是我目前所拥有的:

username_extract = 'lazada_my'

url = 'https://www.instagram.com/'+ username_extract
r = requests.get(url)
soup = BeautifulSoup(r.content,'lxml')
f = soup.find('head', attrs={'class':'count'})

这是我要解析的部分:

enter image description here

我的 soup.find() 函数中有些东西是错误的,但我无法理解它。返回 f 时为空。知道我做错了什么吗?

最佳答案

我认为你可以使用 re 模块来搜索正确的计数。

import requests
import re

username_extract = 'lazada_my'

url = 'https://www.instagram.com/'+ username_extract
r = requests.get(url)
m = re.search(r'"followed_by":\{"count":([0-9]+)\}', str(r.content))
print(m.group(1))

关于python - 获取 Instagram 关注者,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49043857/

相关文章:

C++ 相当于 Python 的 traceback 库

python - 如何在 Python 中从图片的其余部分剪切绿色背景和前景?

python - 类型错误,如果 link.has_attr ('href' ) : TypeError: 'NoneType' object is not callable

python-2.7 - 在 Beautiful Soup 中使用 ="1.0"时如何删除 <?xml version ="utf-8"encoding "xml"?>

instagram - 来自 Instagram 的错误 : The access_token provided does not match an approved application

c# - 从从 Instagram API 检索到的 JSON 字符串中检索 "images"

ios - 从我的 iOS 应用程序将照片分享到 Instagram

python - 使用 Selenium 选择具有特定内容的 anchor

python - BeautifulSoup - 从多个页面获取文本

python - 为 debian 打包 python 程序的简单、直接的方法?