python - 转换 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))
这段代码没有错误,但抓取数据需要太多时间
解决方案
推荐阅读
- javascript - 只读属性在打字稿中部分工作?
- php - 我无法访问 PHP 中的页面
- python - VSCode 中的 Intellisense 和 Python 类型提示
- linux - 如何使用 bash 命令行重命名以序列开头的文件
- mongodb - 如何在 Mongoose 的聚合查询中访问字段值
- python - 跳出 For 循环和 If 语句
- r - 一个一个地绘制二进制向量的条件组合
- kotlin - kotlin:如何制作可滑动的堆栈卡视图?
- ffmpeg - 在 vlc 上接收像素化和滞后的 rtsp 流时
- bash - 在 bash 脚本中包含源代码时,如何修复或屏蔽使用 shellcheck 发现的 1091 错误?