From: 7stud -- Date: 2009-11-09T14:37:30+09:00 Subject: Re: Using Nokogiri Mark Thomas wrote: > This should get what you want: > > prefix = '//div[@class="sectionHeaderText"]/following-sibling::' > xpaths = { > :name => "#{prefix}b/text()", > :addr => "#{prefix}text()[2]", > :citystzip => "#{prefix}text()[3]", > :country => "#{prefix}text()[4]", > :phone => "#{prefix}text()[5]", > } > xpaths.each do |data,xpath| > puts "#{data} = " + doc.search(xpath).to_s.strip > end > > -- Mark. I was wondering if you could answer some xpath questions? I would think that in this xpath: div[@class="sectionHeaderText"]/following-sibling::text()[2] the part: div[@class="sectionHeaderText"]/following-sibling would be the tag. Then: div[@class="sectionHeaderText"]/following-sibling::text() would be the tag's text or "Some Institute name". So then the following [2]: div[@class="sectionHeaderText"]/following-sibling::text()[2] doesn't seem applicable. And in fact, when I run your code, it doesn't work: addr = citystzip = name = Some Institute name country = phone = =========== html =<

Association Detail

DETAIL DIRECTORY RESULTS
Some Institute name

some address
city, st zip
United States
Phone: (123) 456-7890

) Web address: www.xyz.org


Back to Search Results

Search Again ENDOFHTML doc = Nokogiri::HTML.parse(html) prefix = '//div[@class="sectionHeaderText"]/following-sibling::' xpaths = { :name => "#{prefix}b/text()", :addr => "#{prefix}text()[2]", :citystzip => "#{prefix}text()[3]", :country => "#{prefix}text()[4]", :phone => "#{prefix}text()[5]", } xpaths.each do |key, val| puts "#{key} = " + doc.search(val).to_s.strip end -- Posted via http://www.ruby-forum.com/.