WAtir usage

J

junkone

Hi
I found Watir and am excited to use it. I cannot find much examples in
terms of data scraping. I have gotne to a point wherei can use it to
submit form details.
I need to scrape data from the tables etc. How do i do it.
For eg my if ie is my browser object, how do i get the tables in the
page and extract data from 3 table in the page into a array?

Pl help.

Seede
 
X

Xavier Noria

Hi
I found Watir and am excited to use it. I cannot find much examples in
terms of data scraping. I have gotne to a point wherei can use it to
submit form details.
I need to scrape data from the tables etc. How do i do it.
For eg my if ie is my browser object, how do i get the tables in the
page and extract data from 3 table in the page into a array?

Watir is a wrapper around MSIE. In my limited experience crawling
with Watir, besides reading its documentation I think it's good to
study the underlying API, available here:

http://msdn.microsoft.com/library/default.asp?url=/workshop/
browser/mshtml/reference/reference.asp

In particular the interfaces IWebBrowser2, IHTMLDocument2, and
IHTMLDocument3:

http://msdn.microsoft.com/workshop/browser/webbrowser/reference/
ifaces/iwebbrowser2/iwebbrowser2.asp
http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/
document2/document2.asp
http://msdn.microsoft.com/workshop/browser/mshtml/reference/ifaces/
document3/document3.asp

There you see what can be done grabbing the ie attribute of the
Watir::IE object, in case the wrapping interface does not address
some particular need. Additionally, I have found reading watir.rb
very instructive, you have a better knowledge of what you are doing
and may give context and idioms.

-- fxn
 
J

James Britt

Xavier said:
On Jul 8, 2006, at 19:25, (e-mail address removed) wrote:
There you see what can be done grabbing the ie attribute of the
Watir::IE object, in case the wrapping interface does not address some
particular need. Additionally, I have found reading watir.rb very
instructive, you have a better knowledge of what you are doing and may
give context and idioms.

About a year or so ago I poked around trying to get HTML from IE in
Watir. The problem (and maybe this has changed) was that the IE object
did not have a way to get the literal text currently in the browser;
there was no COM 'view|source', so to speak.

What it exposed was access to IE's internal node tree, which is *not*
what is in the browser. IE adds all sorts of things (for DHTML and such,
as well as, I think, the various implied attributes defined in the HTML
DTD. Something akin to the post-schema infoset, I think.) so it is
useless for verifying server output. Still, it is handy in other ways;
you can locate, say, table elements and td content and so on.

I wrote a method that did a recursive walk down the internal IE tree and
created an XML string from it. Contact me off-list if you would like me
to send it to you. It's old and may not work with the current Watir,
but might give you some ideas.

james DOT britt AT gmail DOT com

--
James Britt

http://www.ruby-doc.org - Ruby Help & Documentation
http://www.artima.com/rubycs/ - The Journal By & For Rubyists
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://refreshingcities.org - Design, technology, usability
 
X

Xavier Noria

There you see what can be done grabbing the ie attribute of the
Watir::IE object, in case the wrapping interface does not address
some particular need. Additionally, I have found reading watir.rb
very instructive, you have a better knowledge of what you are doing
and may give context and idioms.

By the way, regarding the question about tables you can do this:

table = ie.table:)index, 3)

That index is 1-based and returns an object of type Watir::Table or
nil. As per the definition of order between tables, it is delegated
to IE this way:

@ieController.document.getElementsByTagName("TABLE")

-- fxn
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,775
Messages
2,569,601
Members
45,182
Latest member
BettinaPol

Latest Threads

Top