From: Soichi Ishida Date: 2013-05-12T08:37:15+09:00 Subject: parse both string and url using Nokogiri xpath ruby 1.9.3 nokogiri 1.5.5 Say, a web page has a link, reference I would like to get both the url and text, "http://example.com" and "reference". First, access to the page that contains this link. doc = Nokogiri::HTML(open(url)) then, name = doc.xpath('//div.../a').text url = doc.xpath('//div.../a/@href).text It works. But the problem is this is parsing twice separately. If you want to apply the same procedure to many links that exist in a single page, it seems inefficient. Is there anyway to produce both url and text by single parse? like def parse_link_and_text (xpath) ... end p parse_link_and_text('//div...') gives a hash => {'reference' => 'http://example.com'} ? -- Posted via http://www.ruby-forum.com/.