Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.46 KB | None | 0 0
  1. import getpass
  2. import requests
  3. import re
  4.  
  5. user = input('Usuario: ')
  6. password = getpass.getpass()
  7.  
  8. s = requests.Session()
  9.  
  10. def do_login(user, password):
  11.     global s
  12.     payload = {
  13.         'do': 'login',
  14.         'url': '/foro/',
  15.         'vb_login_md5password': '',
  16.         'vb_login_md5password_utf': '',
  17.         's': '',
  18.         'vb_login_username': user,
  19.         'vb_login_password': password,
  20.         'logb2': 'Entrar',
  21.         'cookieuser': 1
  22.     }
  23.     response = s.post('https://m.forocoches.com/foro/login.php', data=payload)
  24.     return 'Bienvenido' in response.text
  25.  
  26. def get_number_thread():
  27.     global s
  28.  
  29.     response = s.get('https://m.forocoches.com/foro/newthread.php?do=newthread&f=8')
  30.     text = response.text
  31.     poststarttime = re.search('poststarttime" value="(\d+)"', text).group(1)
  32.     posthash = re.search('posthash" value="([a-f0-9]+)', text).group(1)
  33.     securitytoken = re.search('securitytoken" value="([a-f0-9\-]+)', text).group(1)
  34.     loggedinuser = re.search('loggedinuser" value="(\d+)', text).group(1)
  35.  
  36.     payload = {
  37.         'subject': 'Prueba de hilo',
  38.         'message': 'Prueba de hilo!!<br>',
  39.         'wysiwyg': 1,
  40.         's': '',
  41.         'securitytoken': securitytoken,
  42.         'f': 8,
  43.         'do': 'postthread',
  44.         'posthash': posthash,
  45.         'poststarttime': poststarttime,
  46.         'loggedinuser': loggedinuser,
  47.         'parseurl': 1,
  48.         'signature': 1,
  49.         'sbutton': 'Enviar+Nuevo+Tema'
  50.     }
  51.     url = 'https://m.forocoches.com/foro/newthread.php?do=postthread&f=8'
  52.     response = s.post(url, data=payload)
  53.     print("Hilo creado, {}".format(response.url))
  54.     return int(re.search('"t" value="(\d+)', response.text).group(1))
  55.  
  56. def is_valid_thread(html):
  57.     if 'forumdisplay.php?f=2"' in html:
  58.         if 'serio' not in html.lower():
  59.             return True
  60.     return False
  61.  
  62. def make_poles_starting_at(thread_id):
  63.     global s
  64.     thread_id = thread_id + 1
  65.  
  66.     while(True):
  67.         response = s.get("https://m.forocoches.com/foro/showthread.php?p={}".format(thread_id))
  68.         # Existe el hilo
  69.         if 'Tema especificado.' not in html:
  70.             if is_valid_thread(response.text):
  71.                 url = "https://m.forocoches.com/foro/newreply.php?do=postreply&t={}".format(thread_id)
  72.  
  73.                 text = response.text
  74.                 securitytoken = re.search('securitytoken" value="([a-f0-9\-]+)', text).group(1)
  75.                 loggedinuser = re.search('loggedinuser" value="(\d+)', text).group(1)
  76.  
  77.                 payload = {
  78.                     'message': 'Poleee',
  79.                     'wysiwyg': 0,
  80.                     'styleid': 7,
  81.                     'signature': 1,
  82.                     'fromquickreply': 1,
  83.                     's': '',
  84.                     'securitytoken': securitytoken,
  85.                     'do': 'postreply',
  86.                     't': thread_id,
  87.                     'p': 'who+cares',
  88.                     'parseurl': 1,
  89.                     'loggedinuser': loggedinuser,
  90.                     'sbutton': 'Enviar+Respuesta'
  91.                 }
  92.  
  93.                 response = s.post(url, data=payload)
  94.                 print("Pole hecha en un nuevo hilo => {}".format(response.url))
  95.             thread_id += 1
  96.  
  97. if do_login(user, password):
  98.     print("Login correcto {}".format(user))
  99.     thread_id = get_number_thread()
  100.     print("Continuando a partir del hilo: {}".format(thread_id))
  101.     make_poles_starting_at(thread_id)
  102. else:
  103.     print("Login incorrecto")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement