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. Dr.Batcher 2.3.3 注册码
  2. 用VBS发送短信(飞信)
  3. µTorrent Server初体验
  4. WMI工具:WMI Event Viewer
  5. WriteFile,WriteConsole和_tprintf的一些差别

留下回复