I've written a code for following instagram users. I feed thih code with a list, and it goes user's profile and send request in a loop. But after adding 100-150 people it always gives http 429 error and it says " Sorry, link maybe broken.." in briefly. I already slow down my code it has lots of time.sleep(random(20,50)) but i still get this error. I also add my code scrapy i dont know it is useful. Please help me to find a solution. My code:
class instaFollowSpider(scrapy.Spider):
name = 'instaFollowSpider'
start_urls = ['https://instagram.com']
def parse(self, response):
#Giriş yapma
chrome_options = Options()
chrome_options.add_argument("user-data-dir=C:\\Users\\merta\\AppData\\Local\\Google\\Chrome\\User Data\\Default")
driver = webdriver.Chrome('chromedriver.exe',options=chrome_options)
driver.get('https://instagram.com') # Already authenticated
time.sleep(15)
print("Giriş Yapıldı")
a=0
b=0
baslangic =datetime.now()
#follow process
for i in followlist:
try:
driver.get(f'https://www.instagram.com/{i}/')
time.sleep(random.randint(15,43))
if driver.find_element(By.XPATH, "//div[@class='_aacl _aaco _aacw _aad6 _aade']").text == "Takip Et":
driver.find_element(By.XPATH, "//div[@class='_aacl _aaco _aacw _aad6 _aade']").click()
WebDriverWait(driver, 45).until(EC.visibility_of_element_located((By.XPATH, "//div[@class='_aacl _aaco _aacw _aad6 _aade']")))
b += 1
a = 0
print(i)
time.sleep(random.randint(6, 35))
except NoSuchElementException:
a += 1
if a == 3:
time.sleep(7500)
a=0
continue
else:
time.sleep(random.randint(121, 200))
continue
except:
driver.get_screenshot_as_file(f"screenshot{i}.png")
time.sleep(random.randint(601, 905))
continue
print("Toplam eklenen:", b)
son =datetime.now()
print("Son:",son," |Toplam Çalışma Süresi:",son-baslangic)
process = CrawlerProcess()
process.crawl(instaFollowSpider)
process.start()