Scraping Instagram followers page using selenium and python

后端 未结 2 745
醉酒成梦
醉酒成梦 2021-02-01 11:25

I have a question related to scraping the instagram followers page. I have a code but it displays only 9 followers. Kindly help me.

from selenium import webdrive         


        
2条回答
  •  忘了有多久
    2021-02-01 11:52

    You have to add one for loop so that you can scroll down the page for the followers. This for loop can be like this:

    #Find the followers page
    dialog = driver.find_element_by_xpath('/html/body/div[2]/div/div[2]/div/div[2]')
    #find number of followers
    allfoll=int(driver.find_element_by_xpath("//li[2]/a/span").text) 
    #scroll down the page
    for i in range(int(allfoll/2)):
        driver.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", dialog)
        time.sleep(random.randint(500,1000)/1000)
        print("Extract friends %",round((i/(allfoll/2)*100),2),"from","%100")
    

提交回复
热议问题