문제

So I am using this:

Net::HTTP.get(URI.parse(url))

Works perfect.

Issue I am having is that the page it gets is formatted with head, html, body, etc tags. There is a label element in the body with an id of "Result" I only want to get me back the text of "Result". Not all the html formatting.

Can this be done?

도움이 되었습니까?

해결책

Well, to get only a part of a content in HTML you have to use a HTML parser, which will be Nokogiri in this case .

doc = Nokogiri::HTML(open(url))
doc.css('#Result').each do |re|
  puts re.to_s
  #puts re.content
end
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top