本文实例讲述了Python自动调用IE打开某个网站的方法。分享给大家供大家参考。具体实现方法如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import win32gui
import win32com
import win32com.client
import pythoncom
import time
class Test:
def runtest(self):
print 'test'
class EventHandler:
def OnVisible(self,visible):
global bVisibleEventFired
bVisibleEventFired = 1
def OnDownloadBegin(self):
print 'DownloadBegin'
self.runtest()
self.value = 1
def OnDownloadComplete(self):
print 'DownloadComplete'
self.value += 1
def OnDocumentComplete(self,pDisp=pythoncom.Missing,URL=pythoncom.Missing):
print 'documentComplete of %s' %URL
print self.value
class H(Test,EventHandler):
pass
ie = win32com.client.DispatchWithEvents( 'InternetExplorer.Application' ,H)
ie.Visible = 1
ie.Navigate( "www.jb51.net" )
pythoncom.PumpMessages()
ie.Quit()
|
Copier après la connexion
运行该程序可打开www.jb51.net网站,同时输出如下结果:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 | DownloadBegin
test
DownloadComplete
DownloadBegin
test
DownloadComplete
documentComplete of http:
2
documentComplete of http:
2
DownloadBegin
test
DownloadComplete
documentComplete of http:
2
DownloadBegin
test
DownloadComplete
|
Copier après la connexion
希望本文所述对大家的Python程序设计有所帮助。
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn