From: jbw Date: 2010-03-30T10:36:11+09:00 Subject: Re: how to use string variables in output files? --0015174780a46a10610482faa74d Content-Type: text/plain; charset=UTF-8 Hi, do you want something like this?: require 'hpricot' require 'open-uri' require 'iconv' data = open('http://quotes.money.163.com/corp/1034/code=601398.html').read html = Iconv.iconv("UTF-8//IGNORE","GB2312//IGNORE",data) u8doc = Hpricot(html[0]) tables = u8doc.search("table") i=tables.size puts i for j in 0...i do output = File.new("/Users/jbw/table" + j.to_s + ".html", "w") output.puts tables[j] output.close end On Tue, Mar 30, 2010 at 1:58 AM, Pen Ttt wrote: > hi,i want to prase the web > 'http://quotes.money.163.com/corp/1034/code=601398.html' > there are 27 tables in the web, > i made a for loop to get every table in the web, > /home/pt/test/table0 is the output of tables[0], > /home/pt/test/table1 is the output of tables[1], > ,,,,, > /home/pt/test/table26 is the output of tables[27], > > > here is my programme, > > require 'hpricot' > require 'open-uri' > require 'iconv' > data = > open('http://quotes.money.163.com/corp/1034/code=601398.html').read > html = Iconv.iconv("UTF-8//IGNORE","GB2312//IGNORE",data) > u8doc = Hpricot(html[0]) > tables = u8doc.search("table") > i=tables.size > puts i > for j in 0..i-1 > File.open('/home/pt/test/table'+j.to_s+'.html', 'w') {|f| > f.write('tables['+j.to_s+']'.inner_html) } > end > > it can't work,can you revise it for me? > think you > -- > Posted via http://www.ruby-forum.com/. > > -- jbw --0015174780a46a10610482faa74d--