禁止Firefox终端消息Python/Linux

2024-09-26 17:52:41 发布

您现在位置:Python中文网/ 问答频道 /正文

我是Python编程新手,正在尝试使用Python的webbrowser模块编写一个脚本,用web浏览器打开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

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

^{pr2}$

有什么想法吗?在

谢谢!在

我的整个脚本:

"""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...")

Tags: andtoin脚本webtimeport错误

热门问题