【发布时间】:2020-06-21 08:28:05
【问题描述】:
【问题讨论】:
-
如果你以
python script.py > file.txt运行它,那么它应该保存在file.txt中。最终它还需要将stderr重定向到文件 - 在Linux上你可以做python script.py > file.txt 2>&1
标签: python selenium selenium-chromedriver
【问题讨论】:
python script.py > file.txt 运行它,那么它应该保存在file.txt 中。最终它还需要将stderr 重定向到文件 - 在Linux上你可以做python script.py > file.txt 2>&1
标签: python selenium selenium-chromedriver
我不知道您是如何获得这些消息的,但使用 Google 我在 Chromedriver 文档 Logging 中找到的,它使用这样的设置将一些日志保存在文件 log.txt 中
from selenium import webdriver
driver = webdriver.Chrome(service_args=["--log-path=log.txt"])
#driver = webdriver.Chrome(service_args=["--log-path=log.txt", "--verbose"])
#driver.get('https://stackoverflow.com')
顺便说一句: 在文档中显示通常它会发送到stderr,因此使用2> log.txt 也应该有效。
【讨论】:
stdout 并且重定向 > log.txt 将其发送到文件。但在这个答案中,我不使用重定向。
使用 Try/except 语句,您会收到作为变量的错误消息。
【讨论】:
最简单的方法是在终端手动运行并将stdout(标准输出)重定向到文件
python script.py > output.txt
它可能还需要将stderr(标准错误输出)重定向到文件
python script.py > output.txt 2> error.txt
或将两者重定向到同一个文件
python script.py > output.txt 2>&1
此方法适用于所有在终端中显示内容的程序。
【讨论】:
2>&1 吗?它可能会发送有关标准错误的日志,然后您必须重定向 2>