python - 在 Python 中监控使用 Internet Explorer、Opera、Chrome、Firefox 和 Safari 访问的网站

标签 python internet-explorer safari google-chrome opera

我正在开发一个工作项目,似乎遇到了一个小问题。该项目与 Web Nanny 类似,但以我客户的公司为品牌。它将具有通过 URL、关键字和网络事件日志进行网站拦截等功能。我还需要它能够“暂停”下载,直到输入可接受的用户名和密码。

我找到了一个脚本来监视 Internet Explorer 中访问的 URL(如下所示),但它似乎大大降低了浏览器的速度。我还没有找到任何关于如何在其他浏览器中实现此功能的支持或想法。

所以,我的问题是:

1).如何监控其他浏览器事件/访问的 URL? 2)。除非输入可接受的用户名和密码,否则如何阻止下载?

<小时/>
from  win32com.client import Dispatch,WithEvents
import time,threading,pythoncom,sys

stopEvent=threading.Event()
class EventSink(object):

    def OnNavigateComplete2(self,*args):
        print "complete",args
        stopEvent.set()


def waitUntilReady(ie):
    if ie.ReadyState!=4:
        while 1:
            print "waiting"
            pythoncom.PumpWaitingMessages()
            stopEvent.wait(.2)
            if stopEvent.isSet() or ie.ReadyState==4:
                stopEvent.clear()
                break;

time.clock()
ie=Dispatch('InternetExplorer.Application',EventSink)
ev=WithEvents(ie,EventSink)
ie.Visible=1
ie.Navigate("http://www.google.com")

waitUntilReady(ie)
print "location",ie.LocationName
ie.Navigate("http://www.aol.com")
waitUntilReady(ie)
print "location",ie.LocationName
print ie.LocationName,time.clock()
print ie.ReadyState

最佳答案

我建议寻找一个不错的网络代理。如果机器都在同一网络上,您可以实现透明缓存 Web 代理并在其上放置过滤规则。它们往往速度很快,可以做很多很酷的事情。

我在 Squid 方面运气不错。这能解决您的问题吗?

关于python - 在 Python 中监控使用 Internet Explorer、Opera、Chrome、Firefox 和 Safari 访问的网站,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2994486/

相关文章:

javascript - 下载文件

未在 Safari 6 中设置 Cookie

javascript - iPhone 上的移动菜单不会关闭

python - Matlab 和 Python 中的冒号差异

python - 为什么我安装不了python-Scrapy?

internet-explorer - Internet Explorer 中的 Go 和 gorilla session

javascript - 删除 Internet Explorer 中的事件监听器

python - 如何通过 python mechanize 单击类型 ="button"

python - For 循环遍历 2 的幂

internet-explorer - 关闭由 WScript.CreateObject 创建的 IE 实例