python自动调用ie打开某个网站的方法

本文实例讲述了python自动调用ie打开某个网站的方法。分享给大家供大家参考。具体实现方法如下:

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()

运行该程序可打开www.jb51.net网站,同时输出如下结果:

downloadbegin
test
downloadcomplete
downloadbegin
test
downloadcomplete
documentcomplete of http://pos.baidu.com/acom?adn=0&at=128&aurl=&cad=1&ccd=32&cec=gb2312&cfv=17&ch=0&col=zh-cn&conop=0&cpa=1&dai=1&dis=0&layout_filter=rank%2cimage&ltr=&ltu=http%3a%2f%2fwww.jb51.net%2f&lunum=6&n=jb51_cpr&pcs=1387×729&pis=10000×10000&ps=2348×191&psr=1440×900&pss=1387×2350&qn=6a0cce8cf992d19c&rad=&rsi0=1000&rsi1=60&rsi5=4&rss0=&rss1=&rss2=&rss3=&rss4=&rss5=&rss6=&rss7=&scale=&skin=tabcloud_skin_6&stid=5&td_id=1919103&tn=baiducuststaglinkunit&tpr=1433304842125&ts=1&version=2.0&xuanting=0&dtm=baidu_dup2_setjsonadslot&dc=2&di=u1919103&ti=%e8%84%9a%e6%9c%ac%e4%b9%8b%e5%ae%b6_www.jb51.net&tt=1433304842078.47.125.125
2
documentcomplete of http://www.jb51.net/
2
downloadbegin
test
downloadcomplete
documentcomplete of http://pos.baidu.com/wh/o.htm?ltr=&cf=u
2
downloadbegin
test
downloadcomplete

希望本文所述对大家的python程序设计有所帮助。

发表评论