Get instagram followers

后端 未结 5 621
醉梦人生
醉梦人生 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:19

    You have to look for the scripts, Then look for the 'window._sharedData' exits in it. If exits then perform the regular expression operation.

    import re
    
    username_extract = 'lazada_my'
    url = 'https://www.instagram.com/'+ username_extract
    r = requests.get(url)
    soup = BeautifulSoup(r.content,'lxml')
    s = re.compile(r'"followed_by":{"count":\d*}')
    for i in soup.find_all('script'):
         if 'window._sharedData' in str(i):
             print s.search(str(i.contents)).group()
    

    Result,

    "followed_by":{"count":407426}
    

提交回复
热议问题