Hello, sorry for being too late to reply.
In message "WIN32OLE problems"
on 03/05/08, Martin Kahlert <mkcon / gmx.de> writes:
> require 'win32ole'
> ie = WIN32OLE.new('InternetExplorer.Application')
> ie.visible = true
> ie.Navigate("http://www.ruby-lang.org")
> puts ie.document
>
> but the last line did not work.
>
> So here are my question:
> 1. What's wrong? (You never had guessed that, did you?)
It seems that the Navigate method takes some time to load the page.
And when loading the page is not completed, the document is missing.
So, you wait until loading page is completed.
Try following code.
require 'win32ole'
def navigate(url)
$navigating = false;
end
ie = WIN32OLE.new('InternetExplorer.Application')
ie.visible = true
ev = WIN32OLE_EVENT.new(ie, 'DWebBrowserEvents')
ev.on_event("NavigateComplete") {|url| navigate(url)}
$navigating = true;
ie.Navigate("http://www.ruby-lang.org/");
doc = nil
# wait completing to load the page.
while $navigating
begin
doc = ie.Document
rescue
end
end
puts doc.url
puts doc.charset
# In my environment, the result is
# http://www.ruby-lang.org/ja/
# euc-jp
> 2. Has any method of any server to be coded into WIN32OLE by hand or
> does a WIN32OLE object read what's provided at its creation time?
Neither.
WIN32OLE object tries to invoke the method when the method is called.
For example, the Navigate method of ie called, then
the ie object (WIN32OLE) tries to find the dispatch id of the Navigate,
and tries to invoke the method by using the dispatch id.
> 3. How do i get a list of methods/properties for ie?
> I tried puts ie.methods.join(", "), but this does not give me the
> Navigate method and a lot of other methods, that showed up which i
> tried locked ruby completely.
Try
puts ie.ole_methods.collect {|m| m.name}
Regards,
Masaki Suketa