获取 Instagram 关注者 [英] Get instagram followers

查看:27
本文介绍了获取 Instagram 关注者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I want to parse a website's followers count with BeautifulSoup. This is what I have so far:

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'})

这是我要解析的部分:

我的 soup.find() 函数中的某些内容是错误的,但我无法理解它.当返回 f 时,它是空的.知道我做错了什么吗?

Something within my soup.find() function is wrong, but I can't wrap my head around it. When returning f, it is empty. Any idea what I am doing wrong?

推荐答案

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

I think you can use re module to search the correct count.

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))

这篇关于获取 Instagram 关注者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆