Python自动调用IE打开某个网站的方法

yipeiwu_com6年前Python基础

本文实例讲述了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<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=&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 //www.jb51.net/
2
DownloadBegin
test
DownloadComplete
documentComplete of http://pos.baidu.com/wh/o.htm?ltr=&cf=u
2
DownloadBegin
test
DownloadComplete

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

相关文章

Python3使用SMTP发送带附件邮件

Python3使用SMTP发送带附件邮件

一、设置开启SMTP服务并获取授权码 可以参考第一篇文章,这里不再赘述:【一】/post/142220.htm 二、使用Python3 发送带附件的邮件 0.使用的环境为: Pytho...

python使用flask与js进行前后台交互的例子

flask与js进行前后台交互代码如下,后台给前端发数据: python部分: # -*- coding: utf-8 -*- from flask import Flask,jso...

通过数据库对Django进行删除字段和删除模型的操作

删除字段 从Model中删除一个字段要比添加容易得多。 删除字段,仅仅只要以下几个步骤:     删除字段,然后重新启动你的web服务器。 &nb...

python滑块验证码的破解实现

python滑块验证码的破解实现

破解滑块验证码的思路主要有2种: 获得一张完整的背景图和一张有缺口的图片,两张图片进行像素上的一一对比,找出不一样的坐标。 获得一张有缺口的图片和需要验证的小图,两张图片进行二...

Python使用PyCrypto实现AES加密功能示例

本文实例讲述了Python使用PyCrypto实现AES加密功能。分享给大家供大家参考,具体如下: #!/usr/bin/env python from Crypto.Cipher...