1
我寫了下面的代碼:混淆引入nokogiri :: XML ::#文本的文本輸出
require 'nokogiri'
require 'pp'
html = <<-END
<html>
<head>
<title> A Dirge </title>
<link rel = "schema.DC"
href = "http://purl.org/DC/elements/1.0/">
<meta name = "DC.Title"
content = "A Dirge">
<meta name = "DC.Creator"
content = "Shelley, Percy Bysshe">
<meta name = "DC.Type"
content = "poem">
<meta name = "DC.Date"
content = "1820">
<meta name = "DC.Format"
content = "text/html">
<meta name = "DC.Language"
content = "en">
</head>
<body><pre>
Rough wind, that moanest loud
Grief too sad for song;
Wild wind, when sullen cloud
Knells all the night long;
Sad storm, whose tears are vain,
Bare woods, whose branches strain,
Deep caves and dreary main, -
Wail, for the world's wrong!
</pre></body>
</html>
END
doc = Nokogiri::HTML::DocumentFragment.parse(html)
pp doc
doc.children.each do |ch|
p ch.text if ch.text?
end
但它輸出:
"\n\n \n\n "
"\n\n "
現在我的問題是,爲什麼裏面<pre>
行。 <\pre>
不打印?
任何人都可以幫我解決這個問題嗎?
在一個問題中,將您的輸入數據降低到足以重現問題所需的最小值。在這種情況下,'
'塊都不相關。保留'