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")
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'
# если количество подписчиков больше 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'
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)
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
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}")
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
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: ''
Введите количество человек: 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(',')))
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
file_id = message.photo.file_id
AttributeError: 'NoneType' object has no attribute 'file_id'
in get_photo
file_id = message.photo.file_id
AttributeError: 'list' object has no attribute 'file_id'
file_id = message.photo.file_id
cursor.execute("""CREATE TABLE IF NOT EXISTS usermember (
user_id INTEGER,
username TEXT,
file_id INTEGER
)""")
cursor.execute("INSERT INTO usermember(user_id,username,file_id) VALUES(?,?,?)", (user_id,username,file_id))
user_id = message.from_user.id
username = message.chat.username
username = message.message_text
@bot.message_handler(content_types=['photo'])
def get_photo(message):
#bot.send_photo([-1001573137369], message.photo[-1].file_id)
#bot.send_media_group(message.chat.id, [types.InputMediaPhoto(f, )])
#fileID = message.photo[-1].file_id
fileID = bot.send_media_group(message.chat.id, [types.InputMediaPhoto(f, )])
file_info = bot.get_file(fileID)
bot.send_media_group(message.chat.id, media=media_group)
downloaded_file = bot.download_file(file_info.file_path)
user_path=str(message.from_user.id)
if not os.path.exists(user_path):
os.makedirs(user_path)
with open(str(message.from_user.id) + '/' + fileID, 'wb') as new_file:
new_file.write(downloaded_file)
cursor.execute("SELECT id FROM username_id WHERE id =?", (user_id))
cursor.execute("SELECT id FROM username_id WHERE id =?", (file_id))
@bot.message_handler(commands=['start'])
def start(message):
connect = sqlite3.connect('users.db')
cursor = connect.cursor()
cursor.execute("""CREATE TABLE IF NOT EXISTS username_id (
id INTEGER
)""")
connect.commit()
#Add values in fields
user_id = ["message.chat.id"]
print(type(user_id))
cursor.execute("INSERT INTO username_id VALUES(?);", (user_id))
connect.commit()
cursor.execute("INSERT INTO username_id VALUES(?);", (user_id))
sqlite3.OperationalError: table username_id has 2 columns but 1 values were supplied