1

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()
SuperUser
  • 4,527
  • 1
  • 5
  • 24
  • Did you read [this](https://stackoverflow.com/questions/64769138/how-can-i-bypass-the-429-error-from-www-instagram-com)? – SuperUser Jan 30 '23 at 07:56
  • Yes, there is no retry after response on instagram... – freeengineer Jan 30 '23 at 17:42
  • Then you need to check how much time to wait between requests. Or just use instagram API. – SuperUser Jan 31 '23 at 15:10
  • Canyou give more detail about instagram API. Is it free? If i used it, can i send requests more faster? Can i use it python? I really do not now what is API mean. I researched it but i didn't understand. – freeengineer Feb 01 '23 at 08:08
  • I can't elaborate in the comments but there is plenty of information online. I suggest to use a [python library](https://github.com/adw0rd/instagrapi) for this. – SuperUser Feb 01 '23 at 09:50

0 Answers0