簡體   English   中英

使用 vs 調試器逐步使用並正常運行 Python 的代碼結果差異

[英]Difference of code result using step by step with the vs debugger and running normally Python

您好,我嘗試從帶有硒的網頁中獲取一些數據。 但是有些奇怪的事情發生了,我不明白。 當我使用調試器逐步運行我的程序時,它可以工作,但不能正常運行。 我還沒有在互聯網上看到任何與 python 或 selenium 相關的帖子。 這是我的代碼:

import undetected_chromedriver as uc
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.common.by import By


if __name__ == '__main__':
    L=[]
    PATH="C:\Program Files (x86)\chromedriver.exe"

    options=uc.ChromeOptions()
    pref={"download.default_directory" : r"C:\Users\Dimitri\Documents\Programme C++\clis\extraction+sql\ressources"}
    options.add_experimental_option("prefs",pref)
    options.headless=True
    driver=uc.Chrome(excutable_path=PATH,options=options)
    driver.get("https://framagenda.org/login?redirect_url=/apps/calendar/dayGridMonth/now")
    user = driver.find_element("id","user")
    user.send_keys("user@gmail.com")
    mdp=driver.find_element("id","password")
    mdp.send_keys("test123")
    mdp.send_keys(Keys.RETURN)
    print(driver.title)
    
    
    
    list=driver.find_elements(By.CLASS_NAME,"app-navigation-entry__title")
    for l in list:
        L.append(l.text)


    print(L)


    for l in L:
        driver.get("https://framagenda.org/remote.php/dav/calendars/Dimitri%20L./"+l.lower()+"/?export")

請注意,我不明白問題的第一個 if 我把它放在這里是為了修復我在這個論壇上看到的錯誤

當代碼正常運行時,行 :"list=driver.find_elements(By.CLASS_NAME,"app-navigation-entry__title")" 似乎沒有被執行你知道出了什么問題嗎?

謝謝您的幫助

感謝您的回復,很抱歉不夠清楚。 我終於成功地解決了我的問題。 問題是,當我正常運行代碼時,網頁加載速度不夠快,因此我的程序無法獲取所需的元素,因為網頁沒有加載,盡管當我逐步使用網頁時,網頁有足夠的時間裝載。 在獲取我想要的數據之前,我使用 time.sleep(2) 解決了這個問題

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM