From 7dbd9995f5963c341903070ad834bca4761e6bff Mon Sep 17 00:00:00 2001 From: Arpit Jain Date: Mon, 18 Sep 2023 23:33:12 +0800 Subject: [PATCH] Fix problem description not fetching due to markup change in leetcode I noticed sometimes the div will load but not the content This is working for me --- main.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index f054537..c9fa5e1 100644 --- a/main.py +++ b/main.py @@ -46,16 +46,17 @@ def download(problem_num, url, title, solution_slug): driver.get(url) # Wait 30 secs or until div with class '_1l1MA' appears element = WebDriverWait(driver, 30).until( - EC.visibility_of_element_located((By.CLASS_NAME, "_1l1MA")) + EC.visibility_of_element_located((By.LINK_TEXT, title)) ) # Get current tab page source html = driver.page_source soup = bs4.BeautifulSoup(html, "html.parser") + problem_div = [item for item in soup.find_all() if "data-track-load" in item.attrs][0] # Construct HTML title_decorator = '*' * n problem_title_html = title_decorator + f'
{title}
' + '\n' + title_decorator - problem_html = problem_title_html + str(soup.find("div", {"class": "_1l1MA"})) + '



' + problem_html = problem_title_html + str(problem_div) + '



' # Append Contents to a HTML file with open("out.html", "ab") as f: