Get instagram followers

后端 未结 5 585
醉梦人生
醉梦人生 2020-12-19 23:58

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.         


        
5条回答
  •  囚心锁ツ
    2020-12-20 00:27

    Thank you all, I ended up using William's solution. In case anybody will have future projects, here is my complete code for scraping a bunch of URL's for their follower count:

    import requests
    import csv 
    import pandas as pd
    import re
    
    insta = pd.read_csv('Instagram.csv')
    
    username = []
    
    bad_urls = [] 
    
    for lines in insta['Instagram'][0:250]:
        lines = lines.split("/")
        username.append(lines[3])
    
    with open('insta_output.csv', 'w') as csvfile:
    t = csv.writer(csvfile, delimiter=',')     #   ----> COMMA Seperated
    for user in username:
       try:
           url = 'https://www.instagram.com/'+ user
           r = requests.get(url)
           m = re.search(r'"followed_by":\{"count":([0-9]+)\}', str(r.content))
           num_followers = m.group(1)
           t.writerow([user,num_followers])    #  ----> Adding Rows
       except:
           bad_urls.append(url)
    

提交回复
热议问题