我刚刚开始学习如何使用BeautifulSoup进行网络抓取,并想编写一个简单的程序来获取给定 Instagram 页面的关注者数量。我目前有以下脚本(从另一个问答线程中提取):
import requests
from bs4 import BeautifulSoup
user = "espn"
url = 'https://www.instagram.com/'+ user
r = requests.get(url)
soup = BeautifulSoup(r.content)
followers = soup.find('meta', {'name': 'description'})['content']
follower_count = followers.split('Followers')[0]
print(follower_count)
# 10.7m
Run Code Online (Sandbox Code Playgroud)
我遇到的问题是我想获得一个更精确的数字,当您将鼠标悬停在 Instagram 页面上的关注者计数上时,您可以看到该数字(例如,10,770,816)。
不幸的是,我一直无法弄清楚如何使用 BeautifulSoup 做到这一点。我想在没有 API 的情况下执行此操作,因为我将其与代码相结合以跟踪其他社交媒体平台。有小费吗?