из веб-драйвера импорта селена
из selenium.webdriver.common.by импорт Автор
из параметров импорта selenium.webdriver.firefox.options
время импорта
Код: Выделить всё
# funcion para iniciar el navegador y configurarlo
def prepare_browser(waiting_time=5):
# ruta al perfil de usuario de firefox para cargar cookies
profile_path = "C:\\Users\\donal\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\1om9itxe.default-release"
# darle opciones al navegador
options = Options()
options.add_argument(f"-profile")
options.add_argument(profile_path)
driver = webdriver.Firefox(options=options)
# darle la opcion de iniciar en pantalla completa
driver.maximize_window()
driver.get("https://nintendoproject.com/vip/catalogo-completo-nintendo-switch/")
time.sleep(waiting_time)
return driver
# guardar la devolucion de la funcion
driver = prepare_browser()
# funcion para buscar los links y sacar el nombre de los juegos
# junto con los links y mas informacion de ellos
def get_games_info(driver, waiting_time=5):
# sacar los links que hay en la pagina
game_links = driver.find_elements(By.CSS_SELECTOR, "div > b > span > a")
# bucle para recorrer todos los links y hacerlos textos
with open("first_links.txt", "a+", encoding="utf-8") as file:
# ir al inicio del archivo
file.seek(0)
# leer todas las lineas del archivo y guardarlas en una variable
existing_links = file.readlines()
# abrir un nuevo archivo para escribir los nuevos enlaces
with open("second_links.txt", "a+", encoding="utf-8") as second_file:
# ir al incio del archivo
second_file.seek(0)
# leer los links de este archivo
second_file_read_links = [second_file_read_link.strip() for second_file_read_link in second_file.readlines()]
# iterar sobre los enlaces para abrirlos
for link in existing_links:
link = link.strip()
driver.get(link)
# clase del boton para ir a la siguientep pagina
next_page_button_location = ".elementor-button.elementor-button-link.elementor-size-sm.elementor-animation-float"
# esperar {waiting_time} para que cargue la pagina
time.sleep(waiting_time)
# ubicar el boton y darle click
next_page_button = driver.find_element(By.CSS_SELECTOR, next_page_button_location)
next_page_button.click()
# esperar {waiting_time} para que cargue la pagina
time.sleep(waiting_time)
# localizar las etiquetas a dentro de span para sacarles el enlace
game_download_links = driver.find_element(By.TAG_NAME, "a")
# esperar {waiting_time} para que cargue la pagina
time.sleep(waiting_time)
# sacar el atributo
game_download_link_attributes = game_download_links.get_attribute("href")
print(game_download_link_attributes)
if game_download_link_attributes not in second_file_read_links:
second_file.write(game_download_link_attributes)
get_games_info(driver)
driver.quit()
Код: Выделить всё
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.firefox.options import Options
import time
profile_path = "C:\\Users\\donal\\AppData\\Roaming\\Mozilla\\Firefox\\Profiles\\1om9itxe.default-release"
# darle opciones al navegador
options = Options()
options.add_argument(f"-profile")
options.add_argument(profile_path)
driver = webdriver.Firefox(options=options)
driver.get("https://nintendoproject.com/13-xiii-remake-rom-xci-nsenlaces-vip/")
time.sleep(5)
button = driver.find_element(By.CSS_SELECTOR, ".wp-block-button__link.wp-element-button")
attr = button.get_attribute("href")
print(attr)
button.click()
time.sleep(5)
current_url = driver.current_url
print(current_url)
driver.quit()
Подробнее здесь: https://stackoverflow.com/questions/790 ... -does-in-a