downloading web pages in watir

Discussion in 'Ruby' started by michael, Aug 8, 2006.

  1. michael

    michael Guest

    could anybody tell me how to download web pages accessed through
    watir??

    thanks

    michael
    michael, Aug 8, 2006
    #1
    1. Advertising

  2. michael wrote:
    > could anybody tell me how to download web pages accessed through
    > watir??
    >
    > thanks
    >
    > michael


    While there isn't any methods in Watir to directly download a webpage to
    a file, you can get the HTML content yourself and do your own file
    writing.

    for example;

    ie = Watir::IE.new
    ie.goto('www.google.ca')

    File.open('google.html', "wb") { |f|
    f << '<html>'
    f << ie.html
    f << '</html>'
    }

    Note that the Watir.ie.html method returns the document.body, which does
    not include the opening and closing <html> tags - so you'll need to
    include them in the file writing block.

    --
    Posted via http://www.ruby-forum.com/.
    Brian Cowdery, Aug 8, 2006
    #2
    1. Advertising

  3. michael

    michael Guest

    thanks..


    body is all I want..

    okay.. let's suppose i would like to download 'www.yahoo.com', and save
    it as c:\yahoo\yahoo.htm

    would you show me how I can realize this in ruby, watir??

    thank you so much..


    michael

    Brian Cowdery wrote:
    > michael wrote:
    > > could anybody tell me how to download web pages accessed through
    > > watir??
    > >
    > > thanks
    > >
    > > michael

    >
    > While there isn't any methods in Watir to directly download a webpage to
    > a file, you can get the HTML content yourself and do your own file
    > writing.
    >
    > for example;
    >
    > ie = Watir::IE.new
    > ie.goto('www.google.ca')
    >
    > File.open('google.html', "wb") { |f|
    > f << '<html>'
    > f << ie.html
    > f << '</html>'
    > }
    >
    > Note that the Watir.ie.html method returns the document.body, which does
    > not include the opening and closing <html> tags - so you'll need to
    > include them in the file writing block.
    >
    > --
    > Posted via http://www.ruby-forum.com/.
    michael, Aug 9, 2006
    #3

  4. > Note that the Watir.ie.html method returns the document.body, which does
    > not include the opening and closing <html> tags - so you'll need to
    > include them in the file writing block.


    Also note that Watir does *not* return the actual HTML. It returns the
    DOM, represented as HTML. As an example, HTML generated from Watir's
    "ie.html:" always has closed <p> tags, but the page itself might not.
    This causes trouble sometimes.
    Chris McMahon, Aug 9, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Nathan Sokalski
    Replies:
    5
    Views:
    992
    Gaurav Vaish \(www.Edujini-Labs.com\)
    Jan 10, 2007
  2. Nathan Sokalski
    Replies:
    4
    Views:
    269
    Nathan Sokalski
    Dec 21, 2006
  3. michael
    Replies:
    3
    Views:
    150
    Chris McMahon
    Oct 24, 2006
  4. curious
    Replies:
    1
    Views:
    102
    curious
    Dec 5, 2006
  5. Anukul Singhal
    Replies:
    1
    Views:
    159
    Charley Baker
    May 15, 2008
Loading...

Share This Page