我想解析一个HTML页面,并且只想将所有文本放入<h1>
..<h6>
标记内。
我的实际脚本是:
doc = Nokogiri::HTML(open(s3_page_url).read)
doc.css('h1, h2').each do |link|
puts link.text
end
这是我的测试代码:
html = '<html><head><title><h1>foo</h1><h2>bar</h2></title><body><p>bar</p></body></html>'
doc = Nokogiri::HTML(html)
doc.css('h1').each do |link|
puts link.text
end
这是提示:
foo
问题是我想得到foo bar
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句