I have been trying to scrap all followers from one of my business page which are roughly 50k. I used Selenium web driver and Python to scrap.
I am able to get followers dialogue box and I am able to scroll that dialog box to load more followers. However, the scrolling speed keeps on decreasing as more followers are being loaded in the dialog box.
This technique can work but it will take days. This also requires the machine to be active all of the time & not sleep otherwise the process will stop. And, most of the times it gives an error after 3k to 4k followers scraping.
I was wondering if there is any problem with my script and way of scraping followers or it is usual. And, if there is an efficient way of doing this maybe?
followers_dialoge = driver.find_element_by_xpath("/html/body/div[3]/div[1]/div/div[2]")
n = 1
for i in range(int(allfoll / n)):
next_length = len(driver.find_elements_by_class_name('FPmhX'))
if next_length != prev_length:
new_followers = driver.find_elements_by_class_name('FPmhX')[-12:]
with open(followers_dir, "a") as followers_file:
for element in new_followers:
if element.get_property('href'):
title = element.get_property('title')
href = element.get_property('href')
followers_file.write(title + "," + href + "," + "\n")
During scrolling, every time it loads 12 more followers in the dialog box so in 5th line, I get new 12 followers and save them. I know I can wait for the complete dialog box to load and I can save all 50k once, but as it is prone to stop after a couple of minutes/hours that is why I try to save them during the process. (This can be one reason why it is slow)