Search code examples
pythonseleniumxpathinstagram

Xpath to get total Instagram follower count [Python, Selenium]


I'm putting together a Python script using Selenium that will log into Instagram (my own), and retrieve the total number of followers. I'm having trouble locating the proper Xpath element.

followers= driver.find_element_by_xpath('//*[@id="react-
root"]/section/main/article/header/div[2]/ul/li[2]/a/span')

Using this Xpath turns up nothing.

Has anyone successfully done this before?

Thanks


Solution

  • Following xpath should work

    followers= driver.find_element_by_xpath('.//*[contains(text(), "followers")]/span')