From 086f3361ffa96409fe644d55fd3de2e9b206304a Mon Sep 17 00:00:00 2001 From: joey0629 Date: Tue, 23 Apr 2024 18:58:05 +0800 Subject: [PATCH] Update all headless mode v4 --- main.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 2f8fda7..f9624c4 100644 --- a/main.py +++ b/main.py @@ -87,18 +87,19 @@ def find_pce(date:str): driver = webdriver.Chrome( options=options) try: - print("Successfully accessed the website.") driver.get(pce_url+date) + print("Successfully accessed the website.") time.sleep(0.5) date = driver.find_element(By.XPATH, '//*[@id="home"]/h1').text.split(' ')[4] value_1 = driver.find_element(By.XPATH, '//*[@id="home"]/div[2]/div/div/p[2]').text value_2 = driver.find_element(By.XPATH, '//*[@id="home"]/div[2]/div/div/div[1]/table/tbody/tr[13]').text.strip(' ').split(' ')[-1] - return date , value_1 , value_2 - except WebDriverException: + return date, value_1, value_2 + except WebDriverException as e: + print(e) print("Failed to access the website.") + return None , None , None finally: driver.quit() - return None #非農就業人數 def find_non_farm(url): from selenium import webdriver