Instagram followers/following export error

Viewed 32

Code:

import os
import time
import selenium
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from webdriver_manager.chrome import ChromeDriverManager as CM

from dotenv import load_dotenv
load_dotenv()

# Complete these 2 fields ==================
USERNAME = os.environ.get('INSTA_USER')
PASSWORD = os.environ.get('INSTA_PASS')
# ==========================================

TIMEOUT = 15


def scrape():
    usr = input('[Required] - Whose followers do you want to scrape: ')

    user_input = int(
        input('[Required] - How many followers do you want to scrape (60-500 recommended): '))

    options = webdriver.ChromeOptions()
    # options.add_argument("--headless")
    options.add_argument('--no-sandbox')
    options.add_argument("--log-level=3")
    mobile_emulation = {
        "userAgent": "Mozilla/5.0 (Linux; Android 4.2.1; en-us; Nexus 5 Build/JOP40D) AppleWebKit/535.19 (KHTML, like Gecko) Chrome/90.0.1025.166 Mobile Safari/535.19"}
    options.add_experimental_option("mobileEmulation", mobile_emulation)

    bot = webdriver.Chrome(executable_path=CM().install(), options=options)
    bot.set_window_size(600, 1000)

    bot.get('https://www.instagram.com/accounts/login/')

    time.sleep(2)

    print("[Info] - Logging in...")

    user_element = WebDriverWait(bot, TIMEOUT).until(
        EC.presence_of_element_located((
            By.XPATH, '//*[@id="loginForm"]/div[1]/div[3]/div/label/input')))

    user_element.send_keys(USERNAME)

    pass_element = WebDriverWait(bot, TIMEOUT).until(
        EC.presence_of_element_located((
            By.XPATH, '//*[@id="loginForm"]/div[1]/div[4]/div/label/input')))

    pass_element.send_keys(PASSWORD)

    login_button = WebDriverWait(bot, TIMEOUT).until(
        EC.presence_of_element_located((
            By.XPATH, '//*[@id="loginForm"]/div[1]/div[6]/button')))

    time.sleep(0.5)

    login_button.click()

    time.sleep(5)

    bot.get('https://www.instagram.com/{}/'.format(usr))

    time.sleep(3.5)

    WebDriverWait(bot, TIMEOUT).until(
        EC.presence_of_element_located((
            By.XPATH, '//*[@id="react-root"]/section/main/div/ul/li[2]/a'))).click()

    time.sleep(2)

    print('[Info] - Scraping...')

    users = set()

    for _ in range(round(user_input // 10)):

        ActionChains(bot).send_keys(Keys.END).perform()

        time.sleep(2)

        followers = bot.find_elements_by_xpath(
            '//*[@id="react-root"]/section/main/div/ul/div/li/div/div[1]/div[2]/div[1]/a')

        # Getting url from href attribute
        for i in followers:
            if i.get_attribute('href'):
                users.add(i.get_attribute('href').split("/")[3])
            else:
                continue

    print('[Info] - Saving...')
    print('[DONE] - Your followers are saved in followers.txt file!')

    with open('followers.txt', 'a') as file:
        file.write('\n'.join(users) + "\n")


if __name__ == '__main__':
    scrape()

It gives an error

Error: Özel durum oluştu: TimeoutException Message: Stacktrace: Backtrace: Ordinal0 [0x0112DF13+2219795] Ordinal0 [0x010C2841+1779777] Ordinal0 [0x00FD423D+803389] Ordinal0 [0x01003025+995365] Ordinal0 [0x010031EB+995819] Ordinal0 [0x01030F52+1183570] Ordinal0 [0x0101E844+1108036] Ordinal0 [0x0102F192+1175954] Ordinal0 [0x0101E616+1107478] Ordinal0 [0x00FF7F89+950153] Ordinal0 [0x00FF8F56+954198] GetHandleVerifier [0x01422CB2+3040210] GetHandleVerifier [0x01412BB4+2974420] GetHandleVerifier [0x011C6A0A+565546] GetHandleVerifier [0x011C5680+560544] Ordinal0 [0x010C9A5C+1808988] Ordinal0 [0x010CE3A8+1827752] Ordinal0 [0x010CE495+1827989] Ordinal0 [0x010D80A4+1867940] BaseThreadInitThunk [0x75E2FA29+25] RtlGetAppContainerNamedObjectPath [0x77127B5E+286] RtlGetAppContainerNamedObjectPath [0x77127B2E+238] File "C:\Users\Mert\Downloads\Compressed\Yeni klasör\Insta Scrape\app.py", line 72, in scrape WebDriverWait(bot, TIMEOUT).until( File "C:\Users\Mert\Downloads\Compressed\Yeni klasör\Insta Scrape\app.py", line 106, in scrape()

0 Answers
Related