gpt4 book ai didi

python - 抑制 Firefox 终端消息 Python/Linux

转载 作者:塔克拉玛干 更新时间:2023-11-03 01:17:12 25 4
gpt4 key购买 nike

我是 Python 编程的新手,我正在尝试使用 Python 的 webbrowser 模块制作脚本以通过网络浏览器打开 URL/IP 地址。

打开 Web 浏览器的实际操作工作正常,但我收到来自 firefox 的日志消息,这些消息向我的脚本运行的终端窗口发送垃圾邮件。虽然它最终并没有阻止脚本执行其工作,但由于错误将它们推到了视线之外,因此很难显示提示。

这些错误似乎是在我退出生成的 Firefox 窗口时引起的。这些是所显示错误的示例:

###!!! [Child][MessageChannel] Error: (msgtype=0x460102,name=PContent::Msg_AsyncMessage) Channel closing: too late to send/recv, messages will be lost


###!!! [Child][MessageChannel] Error: (msgtype=0x2C0048,name=PBrowser::Msg___delete__) Channel closing: too late to send/recv, messages will be lost

我试图通过使用命令将错误消息发送到 null 而不是终端来生成 firefox 实例来缓解这种情况,但这没有帮助:

os.system("firefox &> /dev/null"); time.sleep(1)
#before calling below in a while loop. opens tabs in the same window that opens from the above command.
webbrowser.open("http://" + urls.pop(0) + ":" + port,new=2)

有什么想法吗?

谢谢!

我的整个脚本:

"""This script will open URLs and IP addresses in the default web browser.
Please store all URLs and/or IPs in a file called 'port80.txt'.
Please ignore errors that appear in the terminal upon closing your web browser
(may only affect Firefox on Kali Linux).
Thanks."""

import webbrowser
import time
import sys
import os

#sys.tracebacklimit = 0
counter = 0;port = "0"
while port != "80" and port != "443":
port = raw_input("Port 80 or Port 443?\n")

try:
fileOfURLs = open("port"+port+".txt","r")
except:
print("Could not open file. Check if it exists. Exiting...")
exit()

urls = []
readFile = fileOfURLs.readlines()
for line in readFile:
urls.append(line.strip())
fileOfURLs.close()


#get how many urls/IPs are in the file
amountOfURLs = len(urls)
print("There are " + str(amountOfURLs) + " URLs in this text file.")
print("Please ignore error messages upon exit of a FireFox tab/window.\
I have no idea how to stop these...")

"""Open the tabs. Opens 10 at a time over a 10 second span. Change 'maxtabs' to a
different number if more tabs at a time is preferred."""
maxtabs = 10
while amountOfURLs > 0:
os.system("firefox &> /dev/null"); time.sleep(1)
if amountOfURLs > maxtabs:
counter = maxtabs;amountOfURLs -= maxtabs
elif amountOfURLs > 0 and amountOfURLs < maxtabs:
counter = amountOfURLs; amountOfURLs = 0
while counter > 0:
webbrowser.open("http://" + urls.pop(0) + ":" + port,new=2)
counter-=1
print("There are " + str(counter) + " tabs left to open in this batch.")
time.sleep(1)
raw_input("Press enter to continue...")

print("Done.")
raw_input("Press enter to exit...")

最佳答案

我在这里找到了https://github.com/mozilla/geckodriver/issues/1569该声明:“同样,正如在另一个问题上所说,这是 Firefox 的输出,因此与 geckodriver 无关。”这与 https://github.com/mozilla/geckodriver/issues/1376 有关使用 Java 时会出现相同的错误消息。

关于python - 抑制 Firefox 终端消息 Python/Linux,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49499106/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com