billythekid123

Untitled

Nov 21st, 2019
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.00 KB | None | 0 0
  1. from ui.principal import*
  2. from selenium import webdriver
  3. from selenium.webdriver.common.keys import*
  4. import random
  5. import sys
  6. import time
  7.  
  8.  
  9. class Automatiza:
  10. usuario=
  11. senha =
  12.  
  13. hashtags = ['nerd','vingadores']
  14. comentarios = ['legal', 'muito legal o post']
  15.  
  16. links = []
  17.  
  18. preco = 0.0
  19.  
  20. def __init__(self):
  21. self.browser = webdriver.Chrome('C:/chromedriver.exe')
  22. self.login()
  23. self.encontrar()
  24.  
  25.  
  26. def login(self):
  27. self.browser.get('https://www.instagram.com/accounts/login/?source=auth_switcher')
  28. time.sleep(2)
  29.  
  30. campo_usuario = self.browser.find_element_by_xpath("//input[@name='username']")
  31. campo_usuario.clear()
  32. campo_usuario.send_keys(self.usuario)
  33. time.sleep(1)
  34.  
  35. campo_senha = self.browser.find_element_by_xpath("//input[@name='password']")
  36. campo_senha.clear()
  37. campo_senha.send_keys(self.senha)
  38. time.sleep(1)
  39.  
  40. btn_login = self.browser.find_element_by_xpath("//button[@type='submit']")
  41. btn_login.click()
  42. time.sleep(2)
  43.  
  44. def encontrar(self):
  45. self.pegarTopPosts()
  46. self.execute()
  47. self.finalizar()
  48.  
  49. def pegarTopPosts(self):
  50. for hashtag in self.hashtags:
  51. self.browser.get('https://www.instagram.com/explore/tags/' + hashtag +'/')
  52. time.sleep(2)
  53.  
  54. links = self.browser.find_elements_by_tag_name('a')
  55. condicao = lambda link: '.com/p/' in link.get_attribute('href')
  56. links_validos = list(filter(condicao, links))
  57.  
  58. for i in range(0, 9):
  59. link = links_validos[i].get_attribute('href')
  60. if link not in self.links:
  61. self.links.append(link)
  62.  
  63.  
  64. def execute(self):
  65. for link in self.links:
  66. self.browser.get(link)
  67. time.sleep(1)
  68.  
  69. self.browser.execute_script("window.scrollTo(0, document.body.scrollHeight);")
  70. time.sleep(1)
  71.  
  72. self.comentario()
  73. time.sleep(2)
  74.  
  75. self.like()
  76.  
  77. self.preco += 0.02
  78. tempo = random.randint(18, 28)
  79. time.sleep(tempo)
  80.  
  81. def comentario(self):
  82. comentario_input = lambda: self.browser.find_element_by_tag_name('textarea')
  83. comentario_input().click()
  84. comentario_input().clear()
  85.  
  86. comentario = random.choice(self.comentarios)
  87. for coment in comentario:
  88. comentario_input().send_keys(coment)
  89. delay = random.randint(1, 7) / 30
  90. time.sleep(delay)
  91.  
  92. comentario_input().send_keys(Keys.RETURN)
  93.  
  94. def like(self):
  95. btn_like = lambda: self.browser.find_element_by_xpath('//span[@class="glyphsSpriteHeart__outline__24__grey_9 u-__7"]')
  96. btn_like().click()
  97.  
  98. def finalizar(self):
  99. print ('Você realizou $' + str(self.preco) + ' do método hoje.')
  100. self.browser.close()
  101. sys.exit()
  102.  
  103. Automatiza()
Advertisement
Add Comment
Please, Sign In to add comment