それマグで!

知識はカップより、マグでゆっくり頂きます。 takuya_1stのブログ

習慣に早くから配慮した者は、 おそらく人生の実りも大きい。

PythonでWin32comを使えない

るびまを見た。Win32OLE 活用法 【第 7 回】 ほかの言語での COM

さっそく、やってみた。。。動かないOnz

調べてみた。win32comは標準ではインストールされないらしい。RubyMagazineには書いてなかったのだが。記述漏れかな。


Python for Windows 95, 98, NT, 2000, ME, XPを見ると。

Win32all, Mark Hammond's add-on for the regular Python installer (also including the Win32 API, COM support, and Pythonwin), is available from the pywin32 project on SourceForge.

ということらしい。

インストールされると、%PYTHON_PATH%/libs/site-packages/にwin32comがあるはず。

早速、使ってみる(るびまのコード一部修正してる)

import win32com.client

from win32com.server import util


import pythoncom

class WebBrowserEvent :
	def OnDownloadComplete( self, *args, **kwds ):
		print "Download Complete"
	def OnQuite(self, *args, **kwds ):
		exit
ie = win32com.client.DispatchWithEvents("InternetExplorer.Application",WebBrowserEvent)
ie.Visible = True
ie.GoHome()

while ie.ReadyState != win32com.client.constants.READYSTATE_COMPLETE :
	pass

ie.Navigate("http://www.ruby-lang.org/en/")
while ie.ReadyState != win32com.client.constants.READYSTATE_COMPLETE :
	pass
count =0
for element in ie.Document.all:
	count += 1

print "complete\n %d elements found\n" % (count)

を実行して。

Download Complete
Download Complete
Download Complete
Download Complete
complete
 196 elements found

おお。IEが表示されたよ。