This example describes how Python automatically invokes IE to open a Web site. Share to everyone for your reference. The implementation methods are as follows:
?
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 ondownloadbeg In (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.Dispa Tchwithevents (' internetexplorer.application ', H) ie. Visible = 1 ie. Navigate ("Www.jb51.net") pythoncom. Pumpmessages () ie. Quit () |
Run the program to open the Www.jb51.net Web site, and output the following results:
?
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<r=<u=http%3a%2f%2fwww.jb51.net% 2F& lunum=6&n=jb51_cpr&pcs=1387x729&pis=10000x10000&ps=2348x191&psr=1440x900&pss=1387x2350 &qn= 6a0cce8cf992d19c&rad=&rsi0=1000&rsi1=60&rsi5=4&rss0=&rss1=&rss2=&rss3= &rss4=&rss5=&rss6=&rss7=&s cale=&skin=tabcloud_skin_6&stid=5&td_id=1919103& Tn=baiducuststaglinkunit&tpr=1433304842125&ts=1&ve rsion=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
I hope this article will help you with your Python programming.