From 17e8c4ce7f7997497d7030538afb47276511a028 Mon Sep 17 00:00:00 2001 From: Cara Salter Date: Thu, 16 Feb 2023 11:25:48 -0500 Subject: Update to new selenium version --- util.py | 18 ++++++++++-------- 1 file changed, 10 insertions(+), 8 deletions(-) diff --git a/util.py b/util.py index f48ac2b..0c5a134 100644 --- a/util.py +++ b/util.py @@ -11,6 +11,8 @@ import pathlib import base64 from configparser import RawConfigParser +from selenium.webdriver.common.by import By + import requests @@ -242,23 +244,23 @@ def find_cdn(ffx, url, version): page_index = 0; while True: ffx.get(url + f'/files/all?page={page_index}') - mod_versions = ffx.find_elements_by_class_name("listing")[0].find_elements_by_xpath("tbody/tr") # extract the table of files from the page + mod_versions = ffx.find_element(By.CLASS_NAME, "listing").find_elements(By.XPATH, "tbody/tr") # extract the table of files from the page row_info = collections.namedtuple("row_info", ["type", "filename", "cdn_id", "game_version"]) # create a custom tuple because data rows = [] for version_entry in mod_versions: # parse out the four fields that we use - entry_cells = version_entry.find_elements_by_tag_name("td") + entry_cells = version_entry.find_elements(By.TAG_NAME, "td") release_type = entry_cells[0].text # Note that this is NOT the final filename - this is just the "release name". - filename = urllib.parse.quote(entry_cells[1].find_elements_by_tag_name("a")[0].text) + filename = urllib.parse.quote(entry_cells[1].find_elements(By.TAG_NAME, "a")[0].text) try: - game_version = tuple([int(x) for x in entry_cells[4].find_element_by_class_name("mr-2").text.split(".")]) # get game version and convert to tuple + game_version = tuple([int(x) for x in entry_cells[4].find_element(By.CLASS_NAME, "mr-2").text.split(".")]) # get game version and convert to tuple except: if ".".join(map(str, version)) in filename: game_version = version else: game_version = (2, 0, 0) - cdn_id = entry_cells[1].find_element_by_tag_name("a").get_property("href").split("/")[-1] + cdn_id = entry_cells[1].find_element(By.TAG_NAME, "a").get_property("href").split("/")[-1] #TODO make this configurable if 'fabric' not in filename.lower() or 'forge' in filename.lower(): @@ -268,7 +270,7 @@ def find_cdn(ffx, url, version): best_row = next(x for x in rows if x.game_version <= version) break except StopIteration: - if len(ffx.find_elements_by_class_name("pagination-next--inactive")) != 0: + if len(ffx.find_elements(By.CLASS_NAME, "pagination-next--inactive")) != 0: raise page_index += 1 @@ -276,7 +278,7 @@ def find_cdn(ffx, url, version): # We need to find the real, ForgeCDN compatible filename now by going to the file page. ffx.get(f'{url}/files/{best_row.cdn_id}') # This will probably break in the future - filename = ffx.find_elements_by_xpath("html/body/div/main/div/div/section/div/div/div/section/section/article/div/div/span")[1].text + filename = ffx.find_elements(By.XPATH, "html/body/div/main/div/div/section/div/div/div/section/section/article/div/div/span")[1].text # URL escape the filename! filename = urllib.parse.quote(filename) @@ -284,7 +286,7 @@ def find_cdn(ffx, url, version): return f'https://media.forgecdn.net/files/{int(best_row.cdn_id[:4])}/{int(best_row.cdn_id[4:])}/{filename}' except: - # import traceback; traceback.print_exc() + import traceback; traceback.print_exc() print(f"\n[!] Failed to retrieve valid CDN URL for {url}") return None -- cgit v1.2.3