Aquí el código que usaba en ND para verificar los mensajes pendientes que tenía en cada cuenta en ND. También sirve acá (aunque sólo uso una cuenta). Con creatividad se puede modificar el código para hacer cosas más interesantes. Se puede abrir una cuenta GitHub y crear PR's.
Código: Seleccionar todo
#!/usr/bin/env python3
#
# To use:
# 1. Run `pip install --user selenium
# 2. Download geckodriver from https://github.com/mozilla/geckodriver/releases
# 3. Uncompress the above and copy the binary to your $PATH
import os
import sys
from concurrent.futures import ProcessPoolExecutor as Executor
from multiprocessing import cpu_count
from selenium import webdriver
from selenium.common.exceptions import WebDriverException
from selenium.webdriver.common.by import By
CREDENTIALS = [
['verdinegro', 'mypassword'],
]
BROWSER = os.getenv("BROWSER", "firefox")
USER_AGENT = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:77.0) Gecko/20100101 Firefox/77.0'
#URL = "https://www.noticierodigital.com/forum/ucp.php?mode=login"
URL = "https://forond.com/ucp.php?mode=login"
def try_user(credentials):
username, password = credentials
if BROWSER == "firefox":
options = webdriver.FirefoxOptions()
options.headless = True
options.set_preference("general.useragent.override", USER_AGENT)
driver = webdriver.Firefox(options=options, service_log_path=os.devnull)
else:
options = webdriver.ChromeOptions()
options.headless = True
options.add_argument(f"user-agent='{USER_AGENT}'")
driver = webdriver.Chrome(options=options)
with driver:
driver.get(URL)
driver.find_element(by=By.ID, value="username").send_keys(username)
driver.find_element(by=By.ID, value="password").send_keys(password)
driver.find_element(by=By.NAME, value="login").click()
try:
elem = driver.find_element(by=By.ID, value="message")
print(f"{username}: {elem.text.splitlines()[1]}")
except WebDriverException:
elem = driver.find_element(by=By.CLASS_NAME, value='badge')
print(f"{username}: {elem.text if elem.text else '0'}")
def main():
if len(CREDENTIALS) == 1:
try_user(CREDENTIALS[0])
else:
cpus = min(cpu_count(), len(CREDENTIALS))
with Executor(max_workers=cpus) as executor:
executor.map(try_user, CREDENTIALS)
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
sys.exit(1)