亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

為什么我無法從PowerBI網頁中讀取蟒蛇中硒的x路徑

為什么我無法從PowerBI網頁中讀取蟒蛇中硒的x路徑

RISEBY 2022-09-27 10:39:36
我正在嘗試從巴西所在州的網頁上閱讀COVID-19確診病例的數量,但該頁面確實必須從中獲取數據。這是一個 PowerBI 網頁,案例數位于演示文稿的第二頁上。我可以正常地閱讀第一頁的任何內容,但我似乎無法閱讀第二頁的任何內容(在我單擊按鈕切換到下一頁后,該頁面位于頁面的腳注中)。我的代碼是這樣的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()在那里,你有我試圖自動閱讀的網站的URL。我知道代碼不是很好,但我只是想了解硒是如何工作的,以及我如何閱讀這些PowerBI頁面,由于某種原因,這些頁面真的很難閱讀。我嘗試等待很長時間才能加載頁面,但它從未起作用。任何幫助將不勝感激。
查看完整描述

1 回答

?
茅侃侃

TA貢獻1842條經驗 獲得超22個贊

請嘗試以下代碼:


#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


查看完整回答
反對 回復 2022-09-27
  • 1 回答
  • 0 關注
  • 77 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號