在没有 运行 整个脚本的情况下在 Selenium python 中测试 WebScrape?

Testing WebScrape in Selenium python without running whole script?

这可能是一个非常基本的问题,但我正在练习使用 Selenium 抓取动态页面的网络,我想知道是否有一种方法可以只测试 table 部分的网络抓取而无需必须 运行 整个代码?我是一个菜鸟,只是没有看到我做错了什么吗?因为我的代码有很多延迟,以防止在使用 selenium 单击按钮并登录以进入要抓取 table 的页面时出错。但是当我一遍又一遍地测试我的网络抓取以不断等待整个脚本到 运行.

时需要花费很多时间

已将 webdriver.wait 添加到您的脚本并对其进行了简化。

请注意,您必须导入 WebDriverWaitexpected_conditions as EC

from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


driver.get("webpage")
wait = WebDriverWait(driver, 20)

enter_username = input('Enter Username: ')
enter_password = input('Enter Password: ')

wait.until(EC.visibility_of_element_located((By.ID,"UserName"))).send_keys(enter_username) #userbox
wait.until(EC.visibility_of_element_located((By.ID,"Password"))).send_keys(enter_password) #password

driver.switch_to.default_content()

wait.until(EC.visibility_of_element_located((By.CLASS_NAME,"btn-primary"))).click() #email box
wait.until(EC.visibility_of_element_located((By.ID,"portlet"))).click() #smart search box
wait.until(EC.visibility_of_element_located((By.ID,"Search"))).send_keys("Search Results") #search box


try:
    #Code to click captcha checkbox
    #Code to solve recaptcha
except:
    print("Recaptcha did not appear")
    wait.until(EC.visibility_of_element_located((By.ID,"Submit"))).click() #submit box

#def save_Search_Results():
try:
    ***#BeautfiulSoup data This is where I'm testing to save data****
    print(df)