ayuda con Bot de instagram


ThorSkillzz

Miembro muy activo
Se lo que me vais a decir todos. Nunca jamás he tocado python, ni he programado, ni he hecho código, pero quería probar haciendo un bot para instagram y así mataba dos pajaros de un tiro.

EL CASO ES QUE ME DA EL ERROR DE LA IMAGEN (Y SEGURO QUE NO ES EL ÚNICO)
Hay alguien que sepa y que no le importe ayudarme?

Tengo esto, que he ido haciendo con youtube:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep, strftime
from random import randint
import pandas as pd

driver = webdriver.Chrome()
driver.get('https://www.instagram.com/accounts/login/?source=auth_switcher')

username = webdriver.find_element_by_name('dkdkd_kk')
username.send_keys('your_username')
password = webdriver.find_element_by_name('adadadad')
password.send_keys('your_password')

button_login = webdriver.find_element_by_css_selector('#react-root > section > main > div > article > div > div:nth-child(1) > div > form > div:nth-child(3) > button')
button_login.click()
sleep(3)

notnow = webdriver.find_element_by_css_selector('body > div:nth-child(13) > div > div > div > div.mt3GC > button.aOOlW.HoLwm')
notnow.click() #comment these last 2 lines out, if you don't get a pop up asking about notifications

hashtag_list = ['travelblog', 'travelblogger', 'traveler']

# prev_user_list = [] - if it's the first time you run it, use this line and comment the two below
prev_user_list = pd.read_csv('20181203-224633_users_followed_list.csv', delimiter=',').iloc[:,1:2] # useful to build a user log
prev_user_list = list(prev_user_list['0'])

new_followed = []
tag = -1
followed = 0
likes = 0
comments = 0

for hashtag in hashtag_list:
tag += 1
webdriver.get('https://www.instagram.com/explore/tags/'+ hashtag_list[tag] + '/')
sleep(5)
first_thumbnail = webdriver.find_element_by_xpath('//*[@id="react-root"]/section/main/article/div[1]/div/div/div[1]/div[1]/a/div')

first_thumbnail.click()
sleep(randint(1,2))
try:
for x in range(1,200):
username = webdriver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/article/header/div[2]/div[1]/div[1]/h2/a').text

if username not in prev_user_list:
# If we already follow, do not unfollow
if webdriver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/article/header/div[2]/div[1]/div[2]/button').text == 'Follow':

webdriver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/article/header/div[2]/div[1]/div[2]/button').click()

new_followed.append(username)
followed += 1

# Liking the picture
button_like = webdriver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/article/div[2]/section[1]/span[1]/button/span')

button_like.click()
likes += 1
sleep(randint(18,25))

# Comments and tracker
comm_prob = randint(1,10)
print('{}_{}: {}'.format(hashtag, x,comm_prob))
if comm_prob > 7:
comments += 1
webdriver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/article/div[2]/section[1]/span[2]/button/span').click()
comment_box = webdriver.find_element_by_xpath('/html/body/div[3]/div/div[2]/div/article/div[2]/section[3]/div/form/textarea')

if (comm_prob < 7):
comment_box.send_keys('Really cool!')
sleep(1)
elif (comm_prob > 6) and (comm_prob < 9):
comment_box.send_keys('Nice work :)')
sleep(1)
elif comm_prob == 9:
comment_box.send_keys('Nice gallery!!')
sleep(1)
elif comm_prob == 10:
comment_box.send_keys('So cool! :)')
sleep(1)
# Enter to post comment
comment_box.send_keys(Keys.ENTER)
sleep(randint(22,28))

# Next picture
webdriver.find_element_by_link_text('Next').click()
sleep(randint(25,29))
else:
webdriver.find_element_by_link_text('Next').click()
sleep(randint(20,26))
# some hashtag stops refreshing photos (it may happen sometimes), it continues to the next
except:
continue

for n in range(0,len(new_followed)):
prev_user_list.append(new_followed[n])

updated_user_df = pd.DataFrame(prev_user_list)
updated_user_df.to_csv('{}_users_followed_list.csv'.format(strftime("%Y%m%d-%H%M%S")))
print('Liked {} photos.'.format(likes))
print('Commented {} photos.'.format(comments))
print('Followed {} new people.'.format(followed))
 

Adjuntos

  • Captura de pantalla (40).png
    Captura de pantalla (40).png
    102,8 KB · Visitas: 26
Última edición:

Usuario123

Miembro
es que estas usando webdriver.get usa driver.get, todo lo que has puesto de webdriver menos al decir la variable driver es driver.algo
 

Wannadie

reversing & *nix
Nodero
Noder
Te voy a dar un par de consejos:
1. Cuando vas a poner un bloque de código hay una opción para poner código y que sea mas liviano, cuando el código ya es más largo, como es tu caso, sube un archivo.
2. APRENDE PYTHON ANTES!!
 

ThorSkillzz

Miembro muy activo
Te voy a dar un par de consejos:
1. Cuando vas a poner un bloque de código hay una opción para poner código y que sea mas liviano, cuando el código ya es más largo, como es tu caso, sube un archivo.
2. APRENDE PYTHON ANTES!!

Muchas gracias por el consejo 1, no lo sabía srry. Y por lo de python, sí, ojalá, pero tampoco encuentro guías buenas gratis ni tutoriales buenos :S, llevo varios días haciendo búsqueda de información cuando tengo un rato libre, pero bueno, supongo que todo el esfuerzo que haga algún día tendrán su recompensa.