<module>
followers_count, following_count = int(''.join(followers_count.split(','))), int(''.join(following_count.split(',')))
ValueError: invalid literal for int() with base 10: ''
followers_count, following_count = int(''.join(followers_count.split(','))), int(''.join(following_count.split(',')))
if ',' in followers_count or following_count:
followers_count, following_count = int(''.join(followers_count.split(','))), int(''.join(following_count.split(',')))
else:
followers_count, following_count = int(followers_count), int(following_count)
from selenium import webdriver
import time
import random
import requests
import os
import json
from selenium.webdriver.common.keys import Keys
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.chrome.options import Options
random.seed()
#Среднее время между отпиской
unsub_time = 10
# Сколько отписок необходимо сделать
max = int(input("Введите количество человек:\t"))
#Данные для входа
f = open("files/sign.txt", "r")
for line in f:
x = line.split(":")
username = x[0]
password = x[1]
f.close()
browser = webdriver.Firefox(executable_path="driver/geckodriver")
#browser = webdriver.Chrome(executable_path="driver/chromedriver")
# Вход в аккаунт
browser.get("https://www.instagram.com/")
time.sleep(7)
browser.find_element_by_xpath("//section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input").send_keys(username)
browser.find_element_by_xpath("//section/main/article/div[2]/div[1]/div/form/div/div[2]/div/label/input").send_keys(password)
browser.find_element_by_xpath("//section/main/article/div[2]/div[1]/div/form/div[1]/div[3]/button").click()
time.sleep(5)
#Сохранить данные для входа
browser.find_element_by_xpath("//section/main/div/div/div/section/div/button").click()
time.sleep(8)
# Отключить уведомление
#browser.find_element_by_css_selector("button.aOOlW:nth-child(2)")
time.sleep(7)
#sleep(3)
browser.find_element_by_xpath('//button[text()="Не сейчас"]').click()
time.sleep(5)
# метод отписки, отписываемся от всех кто не подписан на нас
browser.get("https://www.instagram.com/" + username)
time.sleep(random.randrange(3, 6))
followers_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a")
followers_count = followers_button.get_attribute("title")
following_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a")
following_count = following_button.find_element_by_tag_name("span").text
time.sleep(random.randrange(3, 6))
# если количество подписчиков больше 999, убираем из числа запятые
if ',' in followers_count or following_count:
followers_count, following_count = int(''.join(followers_count.split(','))), int(''.join(following_count.split(',')))
else:
followers_count, following_count = int(followers_count), int(following_count)
print(f"Количество подписчиков: {followers_count}")
followers_loops_count = int(followers_count / 12) + 1
print(f"Число итераций для сбора подписчиков: {followers_loops_count}")
print(f"Количество подписок: {following_count}")
following_loops_count = int(following_count / 12) + 1
print(f"Число итераций для сбора подписок: {following_loops_count}")
# собираем список подписчиков
followers_button.click()
time.sleep(4)
followers_ul = browser.find_element_by_xpath("/html/body/div[4]/div/div/div[2]")
try:
followers_urls = []
print("Запускаем сбор подписчиков...")
for i in range(1, followers_loops_count + 1):
browser.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", followers_ul)
time.sleep(random.randrange(2, 4))
print(f"Итерация #{i}")
all_urls_div = followers_ul.find_elements_by_tag_name("li")
for url in all_urls_div:
url = url.find_element_by_tag_name("a").get_attribute("href")
followers_urls.append(url)
# сохраняем всех подписчиков пользователя в файл
with open(f"{username}_followers_list.txt", "a") as followers_file:
for link in followers_urls:
followers_file.write(link + "\n")
except Exception as ex:
print(ex)
browser.close()
time.sleep(random.randrange(4, 6))
browser.get(f"https://www.instagram.com/{username}/")
time.sleep(random.randrange(3, 6))
# собираем список подписок
following_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a")
following_button.click()
time.sleep(random.randrange(3, 5))
following_ul = browser.find_element_by_xpath("/html/body/div[4]/div/div/div[2]")
try:
following_urls = []
print("Запускаем сбор подписок")
for i in range(1, following_loops_count + 1):
browser.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", following_ul)
time.sleep(random.randrange(2, 4))
print(f"Итерация #{i}")
all_urls_div = following_ul.find_elements_by_tag_name("li")
for url in all_urls_div:
url = url.find_element_by_tag_name("a").get_attribute("href")
following_urls.append(url)
# сохраняем всех подписок пользователя в файл
with open(f"{username}_following_list.txt", "a") as following_file:
for link in following_urls:
following_file.write(link + "\n")
"""Сравниваем два списка, если пользователь есть в подписках, но его нет в подписчиках,
заносим его в отдельный список"""
count = 0
unfollow_list = []
for user in following_urls:
if user not in followers_urls:
count += 1
unfollow_list.append(user)
print(f"Нужно отписаться от {count} пользователей")
# сохраняем всех от кого нужно отписаться в файл
with open(f"{username}_unfollow_list.txt", "a") as unfollow_file:
for user in unfollow_list:
unfollow_file.write(user + "\n")
print("Запускаем отписку...")
time.sleep(2)
# заходим к каждому пользователю на страницу и отписываемся
with open(f"{username}_unfollow_list.txt") as unfollow_file:
unfollow_users_list = unfollow_file.readlines()
unfollow_users_list = [row.strip() for row in unfollow_users_list]
try:
count = len(unfollow_users_list)
for user_url in unfollow_users_list:
browser.get(user_url)
time.sleep(random.randrange(4, 6))
# кнопка отписки
unfollow_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/div[1]/div[1]/div/div[2]/div/span/span[1]/button")
unfollow_button.click()
time.sleep(random.randrange(4, 6))
# подтверждение отписки
unfollow_button_confirm = browser.find_element_by_xpath("/html/body/div[4]/div/div/div/div[3]/button[1]")
unfollow_button_confirm.click()
print(f"Отписались от {user_url}")
count -= 1
print(f"Осталось отписаться от: {count} пользователей")
# time.sleep(random.randrange(120, 130))
time.sleep(random.randrange(4, 6))
except Exception as ex:
print(ex)
browser.close()
except Exception as ex:
print(ex)
browser.close()
time.sleep(random.randrange(4, 6))
browser.close()
# Завершение работы webdriver
print("\nПрограмма завершена успешно")
#browser.quit()
followers_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a")
following_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a")
followers_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a/span")
followers_count = followers_button.get_attribute("title")
following_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a")
following_count = following_button.find_element_by_tag_name("span").text
followers_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a")
following_count = following_button.find_element_by_tag_name("span").text
Введите количество человек: 2
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:28: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
browser = webdriver.Firefox(executable_path="driver/geckodriver")
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:41: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
browser.find_element_by_xpath("//section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input").send_keys(username)
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:46: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
browser.find_element_by_xpath("//section/main/article/div[2]/div[1]/div/form/div/div[2]/div/label/input").send_keys(password)
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:51: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
browser.find_element_by_xpath("//section/main/article/div[2]/div[1]/div/form/div[1]/div[3]/button").click()
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:54: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
browser.find_element_by_xpath("//section/main/div/div/div/section/div/button").click()
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:60: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
browser.find_element_by_xpath('//button[text()="Не сейчас"]').click()
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:71: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
followers_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a")
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:74: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
following_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a")
C:\Python38\lib\site-packages\selenium\webdriver\remote\webelement.py:341: UserWarning: find_element_by_tag_name is deprecated. Please use find_element(by=By.TAG_NAME, value=name) instead
warnings.warn("find_element_by_tag_name is deprecated. Please use find_element(by=By.TAG_NAME, value=name) instead")
Traceback (most recent call last):
File "F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py", line 81, in <module>
followers_count, following_count = int(''.join(followers_count.split(','))), int(''.join(following_count.split(',')))
ValueError: invalid literal for int() with base 10: ''
Process finished with exit code 1
following_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a")
C:\Python38\lib\site-packages\selenium\webdriver\remote\webelement.py:341: UserWarning: find_element_by_tag_name is deprecated. Please use find_element(by=By.TAG_NAME, value=name) instead
warnings.warn("find_element_by_tag_name is deprecated. Please use find_element(by=By.TAG_NAME, value=name) instead")
Traceback (most recent call last):
File "F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py", line 81, in <module>
followers_count, following_count = int(''.join(followers_count.split(','))), int(''.join(following_count.split(',')))
ValueError: invalid literal for int() with base 10: ''
following_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a")
followers_count, following_count = int(''.join(followers_count.split(','))), int(''.join(following_count.split(',')))
followers_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a/div/span")
followers_count = followers_button.get_attribute("title")
following_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a")
following_count = following_button.find_element_by_tag_name("span").text
followers_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a/div/span")
followers_count = followers_button.get_attribute("title")
following_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a")
following_count = following_button.find_element_by_tag_name("span").text
print(followers_count, following_count, sep='\n')
F:\1samoe_nuzhnoe\PyCharm\Scripts\python.exe F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py
Введите количество человек: 2
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:28: DeprecationWarning: executable_path has been deprecated, please pass in a Service object
browser = webdriver.Firefox(executable_path="driver/geckodriver")
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:41: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
browser.find_element_by_xpath("//section/main/article/div[2]/div[1]/div/form/div/div[1]/div/label/input").send_keys(username)
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:46: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
browser.find_element_by_xpath("//section/main/article/div[2]/div[1]/div/form/div/div[2]/div/label/input").send_keys(password)
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:51: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
browser.find_element_by_xpath("//section/main/article/div[2]/div[1]/div/form/div[1]/div[3]/button").click()
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:54: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
browser.find_element_by_xpath("//section/main/div/div/div/section/div/button").click()
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:60: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
browser.find_element_by_xpath('//button[text()="Не сейчас"]').click()
F:/1samoe_nuzhnoe//PyCharm/otpiska_instagram/instafollowingt8.py:80: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
followers_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[2]/a/div/span")
F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py:83: DeprecationWarning: find_element_by_xpath is deprecated. Please use find_element(by=By.XPATH, value=xpath) instead
following_button = browser.find_element_by_xpath("/html/body/div[1]/section/main/div/header/section/ul/li[3]/a")
C:\Python38\lib\site-packages\selenium\webdriver\remote\webelement.py:341: UserWarning: find_element_by_tag_name is deprecated. Please use find_element(by=By.TAG_NAME, value=name) instead
warnings.warn("find_element_by_tag_name is deprecated. Please use find_element(by=By.TAG_NAME, value=name) instead")
1 945
7 435
Traceback (most recent call last):
File "F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py", line 99, in <module>
followers_count, following_count = int(followers_count.replace), int(following_count.replace)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'builtin_function_or_method'
Process finished with exit code 1
# если количество подписчиков больше 999, убираем из числа запятые
followers_count = followers_count.replace(' ', '').replace(',', '')
following_count = following_count.replace(' ', '').replace(',', '')
print(f"Количество подписчиков: {followers_count}")
followers_loops_count = int(followers_count / 12) + 1
print(f"Число итераций для сбора подписчиков: {followers_loops_count}")
print(f"Количество подписок: {following_count}")
following_loops_count = int(following_count / 12) + 1
print(f"Число итераций для сбора подписок: {following_loops_count}")
followers_loops_count = int(followers_count / 12) + 1
Traceback (most recent call last):
File "F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8_2.py", line 102, in <module>
followers_loops_count = int(followers_count.replace / 12) + 1
TypeError: unsupported operand type(s) for /: 'builtin_function_or_method' and 'int'
Traceback (most recent call last):
File "F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8_3.py", line 119, in <module>
followers_loops_count = int(followers_count / 12) + 1
TypeError: unsupported operand type(s) for /: 'str' and 'int'
if ',' in followers_count or ',' in following_count:
followers_count
или following_count
содержат в себе пустые строки. Как там не оказалось данных - это уже вопрос к коду, с какой страницы были получены такие данные File "F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py", line 87, in <module>
followers_count, following_count = int(followers_count), int(following_count)
ValueError: invalid literal for int() with base 10: '1 945'
ValueError: invalid literal for int() with base 10: ''
followers_count, following_count = int(followers_count), int(following_count)
followers_count, following_count = int(followers_count), int(following_count)
ValueError: invalid literal for int() with base 10: '1 945'
# если количество подписчиков больше 999, убираем из числа запятые
if ',' in followers_count or ',' in following_count:
followers_count, following_count = int(followers_count.replace(',', '')), int(following_count.replace(',', ''))
else:
followers_count, following_count = int(followers_count), int(following_count)
print(f"Количество подписчиков: {followers_count}")
followers_loops_count = int(followers_count / 12) + 1
print(f"Число итераций для сбора подписчиков: {followers_loops_count}")
print(f"Количество подписок: {following_count}")
following_loops_count = int(following_count / 12) + 1
print(f"Число итераций для сбора подписок: {following_loops_count}")
C:\Python38\lib\site-packages\selenium\webdriver\remote\webelement.py:341: UserWarning: find_element_by_tag_name is deprecated. Please use find_element(by=By.TAG_NAME, value=name) instead
warnings.warn("find_element_by_tag_name is deprecated. Please use find_element(by=By.TAG_NAME, value=name) instead")
1 945
7 435
Traceback (most recent call last):
File "F:/1samoe_nuzhnoe/PyCharm/otpiska_instagram/instafollowingt8.py", line 99, in <module>
followers_count, following_count = int(followers_count.replace), int(following_count.replace)
TypeError: int() argument must be a string, a bytes-like object or a number, not 'builtin_function_or_method'
#followers_count, following_count = int(followers_count.replace(',', '')), int(following_count.replace(',', ''))
followers_count, following_count = int(followers_count.replace), int(following_count.replace)
while True:
for i in range(len(followers_count)):
browser.execute_script("arguments[0].scrollTop = arguments[0].scrollHeight", followers_ul)
time.sleep(4)
print(f"Итерация #{i}")
with open(f"{username}_followers_list.txt", "a") as followers_file:
for link in followers_urls:
followers_file.write(link + "\n")