Python自動調用IE開啟某個網站的方法

來源:互聯網
上載者:User

Python自動調用IE開啟某個網站的方法

   本文執行個體講述了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()

  運行該程式可開啟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://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

  希望本文所述對大家的Python程式設計有所協助。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.