I am trying to get the followers count from Instagram. I am using selenium to do the task. Now the structure in which the followers is as follows(This is just to give you an idea. Please check the Instagram website using inspect tool)
[...]
<span class="_ac2a">
<span> 216 </span>
</span>
[...]
The above is the rough structure. I want 216
. When I try the following code I get []
as the result The code:
username = self.username
driver.get(f"https://www.instagram.com/{username}/")
try:
#html = self.__scrape_page()
#page = self.__parse_page(html)
#followers = page.find_all("meta", attrs={"name": "description"})
followers = driver.find_elements(By.XPATH, '//span[@class="_ac2a"]/span')
return followers
# followers_count = (followers[0]["content"].split(",")[0].split(" ")[0])
# return {
# "data": followers_count,
# "message": f"Followers found for user {self.username}",
# }
except Exception as e:
message = f"{self.username} not found!"
return {"data": None, "message": message}
How do I get the followers?
from Selenium - Getting the Text in span tag
No comments:
Post a Comment