From: Pen Ttt on 29 Mar 2010 20:58 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/.
From: Pen Ttt on 30 Mar 2010 07:16 think for your help the right code is : 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 for j in 0..i-1 output = File.new("/home/pt/test/table" + j.to_s + ".html", "w") output.puts tables[j].inner_html output.close end i still have some problems: 1\when i got the table's html,for example tables[2], can i get row size or column size of the tables[2]. 2\can i use array to load the data in the tables[2]?? -- Posted via http://www.ruby-forum.com/.
|
Pages: 1 Prev: It's a fact not lost on the opportunity to see yourself Next: Bind NICs to Mechanize |