我正在一個實時網站上進行交易。現在我想連續廢棄它以提取實時股票或貨幣資料以使用 selenium 和 python 進行計算。我該如何處理。網頁資料不斷更新,并以突出顯示的顏色顯示在所附影像中。每次資料更改時,我都應該能夠提取它并在代碼中進行一些計算。請幫助我實作同樣的目標。

uj5u.com熱心網友回復:
捕獲一維段的 Nifty50 的動態變化值。
您應該使用以下 XPath:
//button[text()='1D']/ancestor::nav//following-sibling::section/descendant::a[text()='Nifty 50']/../following-sibling::td/span
您的有效代碼將是:
driver.maximize_window()
wait = WebDriverWait(driver, 20)
driver.get('https://in.investing.com/')
i = 0
while True:
time.sleep(5)
oneD_Nifty50 = wait.until(EC.visibility_of_element_located((By.XPATH, "//button[text()='1D']/ancestor::nav//following-sibling::section/descendant::a[text()='Nifty 50']/../following-sibling::td/span")))
print(oneD_Nifty50.text)
i = i 1
if i == 10:
break
else:
continue
進口:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
輸出:
17,828.80
17,828.65
17,828.40
17,828.70
17,828.70
17,827.20
17,827.70
17,827.70
17,828.80
17,828.80
Process finished with exit code 0
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/456914.html
下一篇:來自遠程來源的Exiftool
