pedromelocf / automacaoinstagram Goto Github PK
View Code? Open in Web Editor NEWAutomação para interagir automaticamente com o nicho de mercado, com o intuito de gerar engajamento. Foi utilizado o pacote selenium e a navegação através XPATH.
Automação para interagir automaticamente com o nicho de mercado, com o intuito de gerar engajamento. Foi utilizado o pacote selenium e a navegação através XPATH.
Peguei seu codigo pelo youtube, voce respondeu minha msg...
Depois que peguei o código tive que fazer varias alteraçoes devido a versão dos componentes e packs usados... tive dificuldade em capturar o xpath
O código ficou assim...
import random
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.chrome.service import Service
from time import sleep
from random import randint
chrome_driver_path = "chromedriver.exe"
chrome_options = Options()
chrome_options.add_argument("--lang=en-US")
chrome_service = Service(executable_path=chrome_driver_path)
driver = webdriver.Chrome(service=chrome_service, options=chrome_options)
driver.get('https://www.instagram.com/accounts/login/')
sleep(randint(3, 6))
usuario = driver.find_element(By.NAME, "username")
usuario.send_keys('user')
senha = driver.find_element(By.NAME, "password")
senha.send_keys('senha')
button_login = driver.find_element(By.CSS_SELECTOR, '#loginForm > div > div:nth-child(3) > button')
button_login.click()
sleep(randint(4, 8))
hashtag_list = ['casadecampo', 'bookingbrasil', 'carnaval2023', 'rustico', 'flat', 'gravata', 'recife', 'pernambuco',
'viagemcasal', 'hospedagem', 'natureza', 'nature', 'viajar', 'amoviajar', 'comida', 'boraviajar',
'viagembarata', 'caruaru', 'festa', 'gravatape']
tag = -1
likes = 0
comentarios = 0
avancos = 0
choice_hashtag_list = random.choice(hashtag_list)
hashtag_list.remove(choice_hashtag_list)
for hashtag in hashtag_list:
if avancos < 50:
tag += 1
driver.get('https://www.instagram.com/explore/tags/' + random.choice(hashtag_list) + '/')
sleep(6)
thumb_recente = driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[2]/div/div/div/div[1]/div[1]/div[2]/section/main/article/div/div/div/div[1]/div[1]/a/div/div[2]')
thumb_recente.click()
sleep(randint(8, 10))
try:
while avancos < 50:
button_like = webdriver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[3]/div/div/div[1]/div/div[3]/div/div/div/div/div[2]/div/article/div/div[2]/div/div/div[2]/section[1]/span[1]/div')
button_like.click()
likes += 1
sleep(randint(3, 6))
driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[3]/div/div/div[1]/div/div[3]/div/div/div/div/div[2]/div/article/div/div[2]/div/div/div[2]/section[1]/span[2]/div').click()
comment_box = driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[3]/div/div/div[1]/div/div[3]/div/div/div/div/div[2]/div/article/div/div[2]/div/div/div[2]/section[3]/div/form/div/textarea')
sleep(3)
comentario_chance = randint(1, 10)
if comentario_chance == 1:
comment_box.send_keys('Top! Podemos estar enganado, mas acreditamos que tens o necessário para abrir as 7 PORTAS! Eai, VOCÊ TEM CORAGEM?!')
sleep(randint(4, 6))
elif comentario_chance == 2:
comment_box.send_keys('Gostei! Podemos estar enganado, mas acreditamos que tens o necessário para abrir as 7 PORTAS! Eai, VOCÊ TEM CORAGEM?!')
sleep(randint(2, 7))
elif comentario_chance == 3:
comment_box.send_keys('Parabéns! Podemos estar enganado, mas acreditamos que tens o necessário para abrir as 7 PORTAS! Eai, VOCÊ TEM CORAGEM?!')
sleep(randint(4, 10))
elif comentario_chance == 4:
comment_box.send_keys('Amei! Podemos estar enganado, mas acreditamos que tens o necessário para abrir as 7 PORTAS! Eai, VOCÊ TEM CORAGEM?!')
sleep(randint(4, 7))
elif comentario_chance == 5:
comment_box.send_keys('Show! Estávamos aqui olhando seu perfil... Acreditamos que tens o necessário para abrir as 7 PORTAS! Eai, VOCÊ TEM CORAGEM?!')
sleep(randint(1, 3))
elif comentario_chance == 6:
comment_box.send_keys('WOW! Estávamos aqui olhando seu perfil... Acreditamos que tens o necessário para abrir as 7 PORTAS! Eai, VOCÊ TEM CORAGEM?!')
sleep(randint(1, 4))
elif comentario_chance == 7:
comment_box.send_keys('Show de bola! Estávamos aqui olhando seu perfil... Acreditamos que tens o necessário para abrir as 7 PORTAS! Eai, VOCÊ TEM CORAGEM?!')
sleep(randint(3, 7))
elif comentario_chance == 8:
comment_box.send_keys('Curti! Estávamos aqui olhando seu perfil... Acreditamos que tens o necessário para abrir as 7 PORTAS! Eai, VOCÊ TEM CORAGEM?!')
sleep(randint(6, 9))
elif comentario_chance == 9:
comment_box.send_keys('Nossa! Estávamos aqui olhando seu perfil, podemos estar enganados mas... Acreditamos que tens o necessário para abrir as 7 PORTAS! Eai, VOCÊ TEM CORAGEM?!')
sleep(randint(1, 12))
elif comentario_chance == 10:
comment_box.send_keys('Muito bom! Estávamos aqui olhando seu perfil, podemos estar enganados mas... Acreditamos que tens o necessário para abrir as 7 PORTAS! Eai, VOCÊ TEM CORAGEM?!')
sleep(randint(4, 12))
comment_box.send_keys(Keys.ENTER)
comentarios += 1
sleep(randint(2, 10))
if avancos == 0:
avancar_postagem = driver.find_element(By.XPATH, '/html/body/div[2]/div/div/div[3]/div/div/div[1]/div/div[3]/div/div/div/div/div[1]/div/div/div/button')
avancar_postagem.click()
sleep(randint(5, 10))
avancos += 1
elif avancos % 5 == 0:
avancos += 1
break
else:
avancar_postagem = driver.find_element(By.XPATH,
'/html/body/div[2]/div/div/div[3]/div/div/div[1]/div/div[3]/div/div/div/div/div[1]/div/div/div/button')
avancar_postagem.click()
sleep(randint(5, 10))
avancos += 1
except:
continue
else:
print('Liked {} fotos'.format(likes))
print('Comentários {} fotos'.format(comentarios))
Mas alguma coisa esta acontecendo, pois ele abre as fotos mais nao curte e nem comenta, e ai ja vai pra proxima hashtag e clica em outra foto mas nao curte e nem comenta... voce pode me ajudar?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.