我正在嘗試從巴西所在州的網(wǎng)頁上閱讀COVID-19確診病例的數(shù)量,但該頁面確實(shí)必須從中獲取數(shù)據(jù)。這是一個(gè) PowerBI 網(wǎng)頁,案例數(shù)位于演示文稿的第二頁上。我可以正常地閱讀第一頁的任何內(nèi)容,但我似乎無法閱讀第二頁的任何內(nèi)容(在我單擊按鈕切換到下一頁后,該頁面位于頁面的腳注中)。我的代碼是這樣的from selenium import webdriverfrom time import sleepfrom selenium.webdriver.common.by import Byfrom selenium.webdriver.support.ui import WebDriverWaitfrom selenium.webdriver.support import expected_conditions as ECclass PowerBIBot: def __init__(self): self.driver = webdriver.Chrome() self.driver.get("https://app.powerbi.com/view?r=eyJrIjoiMDgwOGI4YjItNGFjNC00ZThkLWIyNzctMmNjZTQxMmU1ZjRhIiwidCI6Ijg3ZTRkYTJiLTgyZGYtNDhmNi05MTU3LTY5YzNjYTYwMGRmMiIsImMiOjR9&fbclid=IwAR1U64ZAVQ0IZ9RkiZnO7K7ysbvGtAGHCJWqIbIG8Z7SBfcM8hLSv7B2JSU") sleep(8) test = self.driver.find_element_by_xpath("/html/body/div[1]/ui-view/div/div[1]/div/div/div/div/exploration-container/exploration-container-legacy/div/div/exploration-host/div/div/exploration/div/explore-canvas-modern/div/div[2]/div/div[2]/div[2]/visual-container-repeat/visual-container-modern[3]/transform/div/div[3]/visual-modern/div/div") # This works print(test) self.driver.find_element_by_xpath('/html/body/div[1]/ui-view/div/div[2]/logo-bar/div/div/div/logo-bar-navigation/span/a[3]/i') \ .click() sleep(8) try: element = WebDriverWait(self.driver, 25).until(EC.presence_of_element_located((By.XPATH, "/html/body/div[1]/ui-view/div/div[1]/div/div/div/div/exploration-container/exploration-container-legacy/div/div/exploration-host/div/div/exploration/div/explore-canvas-modern/div/div[2]/div/div[2]/div[2]/visual-container-repeat/visual-container-modern[3]/transform/div/div[3]/visual-modern/div/svg/g[1]/text"))) print(element) finally: passPowerBIBot()在那里,你有我試圖自動(dòng)閱讀的網(wǎng)站的URL。我知道代碼不是很好,但我只是想了解硒是如何工作的,以及我如何閱讀這些PowerBI頁面,由于某種原因,這些頁面真的很難閱讀。我嘗試等待很長時(shí)間才能加載頁面,但它從未起作用。任何幫助將不勝感激。
1 回答

茅侃侃
TA貢獻(xiàn)1842條經(jīng)驗(yàn) 獲得超22個(gè)贊
請嘗試以下代碼:
#click next page
WebDriverWait(self.driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "i[title='Next Page']"))).click()
try:
elements = WebDriverWait(self.driver, 25).until(EC.presence_of_all_elements_located((By.XPATH, "//*[@class='card' and @aria-label != '']")))
for element in elements:
print(element.get_attribute('aria-label'))
finally:
pass
添加回答
舉報(bào)
0/150
提交
取消