Skip to content

Instantly share code, notes, and snippets.

@todmephis
Created February 22, 2017 19:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save todmephis/d9a27234fde6175121c581ff0864c85d to your computer and use it in GitHub Desktop.
Save todmephis/d9a27234fde6175121c581ff0864c85d to your computer and use it in GitHub Desktop.
Tag automatically your friends on Facebook post using python. | Etiqueta automaticamente a tus amigos en un post de Facebook usando python.
#!/usr/bin/python
# -*- coding: utf-8 -*-
"""
Autotag Facebook V 1.0
Copyright (C) 2017 todmephis
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
_ _
__ _ _ _| |_ ___ | |_ __ _ __ _
/ _` | | | | __/ _ \| __/ _` |/ _` |
| (_| | |_| | || (_) | || (_| | (_| |
\__,_|\__,_|\__\___/ \__\__,_|\__, |
|___/
__ _ _ _ ___
/ _| __ _ ___ ___| |__ ___ ___ | | __ __ _/ | / _ \
| |_ / _` |/ __/ _ \ '_ \ / _ \ / _ \| |/ / \ \ / / || | | |
| _| (_| | (_| __/ |_) | (_) | (_) | < \ V /| || |_| |
|_| \__,_|\___\___|_.__/ \___/ \___/|_|\_\ \_/ |_(_)___/
___ __
(_) \ / /
_ \ V /
(_) \_/ by todmephis
Requerimientos:
python 2 (obvio :v)
selenium
splinter
FireFox
geckodriver
$pip install selenium
$pip install splinter
$apt-get install firefox
Para geckodriver descarga el release adecuado a tu arquitectura:
*https://github.com/mozilla/geckodriver/releases
*Descomprimes
*chmod +x geckodriver
*Exportas su ruta a $PATH
si no haces este paso tendrás que especificar la ruta en la función Browser
Instrucciones:
*En la función iniciarSesionFacebook() indica en los parametros tu email y password
respectiamente.
**Nota: Recuerda aprovar el login si tienes autenticación en dos pasos.
*En la función autotag() en la lista papus[], escribir la etiqueta como lo harías en
facebook. Ex. "@Ivan Sanc"...
**Nota: Si en tus contactos hay dos personas con el mismo nombre asegúrate de dar más
caracteres hasta que tu objetivo sea el único que salga en la lista de etiquetas en
facebook y así asegurar el correcto etiquetado.
*La lista papus[] se puede llenar con cero o más contactos.
*En la función autotag() en la variable zelda_publicación va el zelda permanente de la
publicación en donde se realizarán las etiquetas; este lo obtienes dando click en la hora
de la publicación.
*En la función autotag() en la variable comment_box_id va el ID de la caja de comentarios
de esa publicación.
**Nota: Para obtener este ID solo basta con inspeccionar el elemento y dar click en el box
que dice "Write your comment here...".
El código se ve de esta forma:
<div id="addComment_XXXXXXXXXXXXXXX" class="UFIRow _4oep UFIAddComment
UFIAddCommentWithPhotoAttacher _2o9m"
data-ft="{&quot;tn&quot;:&quot;[&quot;}">
<div class="UFIMentionsInputWrap UFIStickersEnabledInput
clearfix" direction="left"><div class="_ohe lfloat">
*El número de etiquetas se ingresa en tiempo de ejecución o puedes modificar el código si gustas.
Cualquier pedo me escriben en:
https://facebook.com/todmephisoficial/
https://twitter.com/todmephis
Telegram: @todmephis
Hecho por un man sin nada que hacer :v :v V:V:V::V::V:VVVV
"""
import time
from selenium.webdriver.common.keys import Keys
from splinter import Browser
browser = Browser()
print "Abriendo facebook.com..."
browser.visit('https://facebook.com')
time.sleep(5)
def iniciarSesionFacebook(correo, contrasena):
print "Iniciando sesión...\n "
browser.fill('email', correo)
browser.fill('pass', contrasena)
time.sleep(2)
browser.find_by_id('u_0_q').click()
time.sleep(1)
if browser.is_element_present_by_id('approvals_code'):
print "Tienes 20 segundos para ingresar el código para iniciar sesión\n"
time.sleep(20)
url = browser.url
if url == "https://www.facebook.com/":
print "Inicio de sesión correcto :)\n"
time.sleep(4)
def autotag():
papus=["@Juan Perez", "@Pepe Botella"]#Ingresa las primeras letras de los papu a etiquetar
zelda_publicacion = "https://www.facebook.com/groups/ESCOM/permalink/xxxxxxxxxxxx/" #Zelda de la publicacion
comment_box_id = "addComment_xxxxxxxxxxxxxxx" #Inspecciona elemento y busca el ID de la caja de texto e inserta aquí
time.sleep(2)
print "Abriendo zelda"
browser.visit(zelda_publicacion)
cuantas_etiquetas = int(raw_input('Cuantas etiquetas?-> '))
i=0
while (i<cuantas_etiquetas):
for j in papus:
browser.find_by_id(comment_box_id).click()
time.sleep(3)#by todmephis
browser.find_by_id(comment_box_id).type(j)
time.sleep(3)
browser.find_by_id(comment_box_id).type('\n')
time.sleep(3)
browser.find_by_id(comment_box_id).type('\n')
time.sleep(3)
print "%d-> Papu etiquetado :v" % (i+1)
time.sleep(5)
browser.reload()
i=i+1
print "mi trabajo aquí ha terminado :v :v :v xdxDXdXDxddds"
browser.quit()
iniciarSesionFacebook("email@email.com", "mipass")#Parametros: Correo y contraseña
autotag()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment