|
|
|
@ -60,16 +60,18 @@ def find_indicate(url): |
|
|
|
|
def find_cpi(url): |
|
|
|
|
from selenium import webdriver |
|
|
|
|
from selenium.webdriver.common.by import By |
|
|
|
|
from selenium.webdriver.chrome.options import Options |
|
|
|
|
from selenium.webdriver.firefox.options import Options |
|
|
|
|
from selenium.webdriver.support.ui import WebDriverWait |
|
|
|
|
from selenium.webdriver.support import expected_conditions as EC |
|
|
|
|
import time |
|
|
|
|
# options.add_argument("--headless") # 啟用無頭模式 |
|
|
|
|
driver = webdriver.Edge() |
|
|
|
|
options = Options() |
|
|
|
|
options.add_argument("--headless") # 啟用無頭模式 |
|
|
|
|
driver = webdriver.Firefox(options = options) |
|
|
|
|
driver.get(url) |
|
|
|
|
# time.sleep(3) |
|
|
|
|
date = driver.find_element(By.XPATH, '//*[@id="bodytext"]/div[1]/pre[1]').text.split('\n')[6].split("-")[1].split(" ")[1] |
|
|
|
|
value = driver.find_element(By.XPATH, '//*[@id="bodytext"]/div[1]/pre[1]').text.split('\n')[8:12] |
|
|
|
|
driver.quit() |
|
|
|
|
return date , value |
|
|
|
|
# 是一個持續運行的迴圈,不斷從Telegram伺服器抓取新的消息 |
|
|
|
|
# 然後使用上面定義的消息處理器來處理這些消息。 |
|
|
|
@ -168,4 +170,5 @@ if __name__ == "__main__": |
|
|
|
|
#CPI |
|
|
|
|
|
|
|
|
|
# data, value = find_cpi(cpi_url) |
|
|
|
|
# print(data, value) |
|
|
|
|
# read_CPI(cpi_url) |