Gegeben:Wie mache ich eine Regex-Suche in Nokogiri nach Text, der einem bestimmten Anfang entspricht?
require 'rubygems'
require 'nokogiri'
value = Nokogiri::HTML.parse(<<-HTML_END)
"<html>
<body>
<p id='para-1'>A</p>
<div class='block' id='X1'>
<h1>Foo</h1>
<p id='para-2'>B</p>
</div>
<p id='para-3'>C</p>
<h2>Bar</h2>
<p id='para-4'>D</p>
<p id='para-5'>E</p>
<div class='block' id='X2'>
<p id='para-6'>F</p>
</div>
</body>
</html>"
HTML_END
ich so etwas tun will, was ich in Hpricot tun kann:
divs = value.search('//div[@id^="para-"]')
- Wie für Elemente in XPath Stil ein Muster Such ich tun?
- Wo finde ich die Dokumentation, die mir hilft? Ich habe das in den Rdocs nicht gesehen.
PSA: Für diejenigen, komplexere regex versucht, dies ist wahrscheinlich, was Sie suchen: http://stackoverflow.com/questions/649963/ nokogiri-suche-nach-div-using-xpath – DreadPirateShawn