Archive

Posts Tagged ‘scraping’

use watir for Page scraping

October 5th, 2008 No 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: ,