首页 > 解决方案 > 转换 Python selenium 代码以更快地工作

问题描述

下面的代码工作正常,但花费了太多时间。有什么办法可以让我更快地做到这一点?我尝试了 BeautifulSoup,但无法获取嵌套表条目数据。谁能帮助如何以更快的方式完成这项工作?

from selenium import webdriver


options = webdriver.ChromeOptions()
#options.add_argument("headless")
browser = webdriver.Chrome(chrome_options=options)
browser.get(my_url)
table = browser.find_element_by_id("testModuleViewerGrid")
tbody = table.find_element_by_tag_name("tbody")
rows = tbody.find_elements(By.TAG_NAME, "tr")  # get all of the rows in the table

for row in rows:
    module_name = row.find_elements(By.TAG_NAME, "td")[0]
    module_status = row.find_elements(By.TAG_NAME, "td")[2]
    module_status_value = row.find_elements(By.TAG_NAME, "span")[0]
    test_name.append((module_name.text))
    test_status.append((module_status_value.text))

这段代码没有错误,但抓取数据需要太多时间

标签: pythonseleniumbeautifulsoup

解决方案


推荐阅读