Python调用COM组件

标签: , ,

初学 Python 的时候就研究过怎样调用 COM 组件,这样就能像写 VBScript 一样写 Python,那时就想写一篇关于 Python 调用 COM 组件的文章,但是一直都没有写。

简单的写一下吧,用 Python 调用 COM 组件需要 pywin32 模块的支持,ActivePython 默认已经安装了,没有安装的话安装一下。下面以 Msxml2.XMLHTTP 为例简单说一下用法:

#Author: Demon
#Date: 2011/12/20
#Website: https://demon.tw
import win32com.client
http = win32com.client.Dispatch('Msxml2.XMLHTTP')
http.open('GET', 'https://demon.tw', False)
http.send()
print http.responseText

除了把 VBS 的 CreateObject 函数替换成 win32com.client.Dispatch 以外,其他基本都一样。

赞赏

微信赞赏支付宝赞赏

随机文章:

  1. OpenWrt路由器WIFI开启13信道
  2. EditPlus 3.30
  3. BAT批处理编辑器Visual Bat
  4. VBS转EXE工具:Vbs2Exe
  5. 在Windows下源码编译PHP

留下回复