WIN32OLE problems

Hi!
In the thread "Howto get source code of displayed IE-pages?"
Chris Morris gave me a link to OLE-documentation for the
internet explorer. (Thanks a lot, Chris!)

I tried this code in order to get the source of a page:

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.
My second guess ie[“Document”] does not work, either.
IIRC i got a missing method error.

So here are my question:

  1. What’s wrong? (You never had guessed that, did you?)

  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?

  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.

Thanks for any help
Martin.

puts ie.document

but the last line did not work.

You have to poke around the documentation to sort of figure out the right
way to do things – it’s not always obvious:

S:\SF-scrapware\scrapware\cliecontroller>more test.rb
require ‘win32ole’
@ie = WIN32OLE.new(‘InternetExplorer.Application’)
@ie.visible = true
@ie.Navigate(“http://www.ruby-lang.org”)

S:\SF-scrapware\scrapware\cliecontroller>irb
irb(main):001:0> require ‘test’
true
irb(main):002:0> @ie.document # … is just another COM object
#WIN32OLE:0x2ade498
irb(main):003:0> @ie.document.documentElement.innerHtml
"Ruby Home Page\r\n<META http-equiv=Content-Type
content="
text/html; charset=ISO-8859-1">\r\n<META content="tDiary 1.5.2"
name=generato

@ie.document.documentElement is rather non-intuitive, IMO, but the MSDN docs
have it in there. I had to dig a little to find it.

Chris
http://clabs.org/blog

Hi,

mkcon@gmx.de (Martin Kahlert) wrote:

So here are my question:

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
You can try out “soleb”, an OLE browser written in ruby. Its
author is the same with WIN32OLE library, Masaki Suketa.
You can download it from the link below.

http://homepage1.nifty.com/markey/ruby/win32ole/index_e.html

Or, you can use the OLE browser that comes with ActivePerl 5.8.
It works great.

Thanks for any help
Martin.

Takashi Sano

···

Technical Writer/Translator
Takashi Sano
E-mail: tksano@m3.kcn.ne.jp
URL: http://www3.kcn.ne.jp/~tksano/

Hello, sorry for being too late to reply.

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

オブジェクト指向スクリプト言語 Ruby

euc-jp

  1. 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.

  1. 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

···

In message “WIN32OLE problems” on 03/05/08, Martin Kahlert mkcon@gmx.de writes: