Home > watir > use watir for Page scraping

use watir for Page scraping

October 5th, 2008 Leave a comment Go to comments

The following is the code to use watir for Page scraping:

require ‘watir’
include Watir

jinan = “http://homemsg.focus.cn/msgview/607/48996344.html”

ie21 = IE.new
ie21.goto jinanba

puts ie21.table(:index => 9, :class => /p9/).text

#puts ie21.table(:index => 11, :class => /p9/).html

The following is the code to use firewatir for Page scraping, the reson to use firewatir is that the watir will wait for the page load:

require ‘firewatir’
include FireWatir

jinanba = “http://homemsg.focus.cn/msgview/607/48996344.html”

ie21 = Firefox.new
ie21.goto jinanba

fout = File.new(“test.txt”, “w”)
fout.puts ie21.table(:index , 16).html
fout.close



Categories: watir Tags: ,
  1. No comments yet.
  1. No trackbacks yet.
      
                  
      

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word