Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/346.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 我如何才能快速获得Instagram大量用户的关注人数?_Python_Performance_Web Scraping_Instagram - Fatal编程技术网

Python 我如何才能快速获得Instagram大量用户的关注人数?

Python 我如何才能快速获得Instagram大量用户的关注人数?,python,performance,web-scraping,instagram,Python,Performance,Web Scraping,Instagram,我有一个python程序,它读取Instagram帐户1390680个URL的列表,并获取每个用户的跟随者数量。它使用instaloader。代码如下: 将熊猫作为pd导入 从instaloader导入instaloader,配置文件 # 1. 加载数据 #从csv中读取数据 数据=pd.read\u csv('IG\u Audience.csv')) #获取配置文件URL URL=数据['Profile URL'] def getFollowerCount(配置文件): #使用instaloa

我有一个python程序,它读取Instagram帐户1390680个URL的列表,并获取每个用户的跟随者数量。它使用instaloader。代码如下:

将熊猫作为pd导入
从instaloader导入instaloader,配置文件
# 1. 加载数据
#从csv中读取数据
数据=pd.read\u csv('IG\u Audience.csv'))
#获取配置文件URL
URL=数据['Profile URL']
def getFollowerCount(配置文件):
#使用instaloader模块从该编程器获取跟随者计数
# https://stackoverflow.com/questions/52225334/webscraping-instagram-follower-count-beautifulsoup
尝试:
L=Instaloader()
profile=profile.from_用户名(L.context,profile)
打印(配置文件'has',PROFILE.followers',followers')
返回(profile.followers)
例外情况除外:
打印(例外,错误)
返回(0)
#跟随者计数表
followerCounts=[]
#此循环将获取每个用户的跟随者计数
对于url中的url:
#通过删除instagram.com从URL获取配置文件用户名
#部分和url末尾的反斜杠
url\u dirty=url.replace('https://www.instagram.com/', '')
url\u clean=url\u dirty[:-1]
追加(getFollowerCount(url_clean))
#将列表转换为系列,将其添加到数据帧,然后将其写入
#csv
数据['followercount']=pd.系列(followerCounts)
data.to_csv('IG_academy.csv'))

我的主要问题是要花很长时间才能看完整个清单。仅获得3035名用户的关注人数就花了14个小时。有没有办法加快这个过程?

瓶颈在哪里?有时我会收到这样的错误消息:JSON查询到(某个用户名)/feed/:429请求太多:重定向到登录[retrying;跳过^C]HTTP错误代码429返回,因为上一次发生的查询太多。请不要在浏览器中使用Instagram或并行运行Instaloader的多个实例。请求将在666秒后17:58重试。但是,在经过一段时间后,它将恢复。您正在每个循环中创建一个新的Instaloader。也许只是在循环外创建一个并调用它?有查询速率限制吗?你坚持吗?周期性的666秒延迟是您试图缓解的主要问题吗?你读到瓶颈在哪里了吗?有时我会收到以下错误消息:JSON查询到(某个用户名)/feed/:429请求太多:重定向到登录[retrying;跳过^C]HTTP错误代码429返回,因为上次发生的查询太多。请不要在浏览器中使用Instagram或并行运行Instaloader的多个实例。请求将在666秒后17:58重试。但是,在经过一段时间后,它将恢复。您正在每个循环中创建一个新的Instaloader。也许只是在循环外创建一个并调用它?有查询速率限制吗?你坚持吗?周期性的666秒延迟是您试图缓解的主要问题吗?你读了吗