所以我写了一个刮刀,我试图只得到包含 On Snow Feel
的段落文本我试图将其拉出来,但我不确定如何让nokogiri拉出具有匹配文字的段落。
目前我有boards[:onthesnowfeel] = html.css(".reviewfold p").text
,但这会抓住所有段落。并且不要假设段落将始终按顺序排列。所以不能做[2]或其他什么。
但是你会使用什么方法来刮取与“On Snow Feel”文本相匹配的段落
<div id="review" class="reviewfold">
<p>The <strong>Salomon A</strong><b>assassin</b> Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. </p>
<p><b>Approximate Weight</b>: Moew mix is pretty normal</p>
<p><strong>On Snow Feel: </strong>At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum.</p>
<p><strong>Powder: </strong>It is a long established fact that a reader will be distracted by the readable content of a page when looking at its layout. </p>
</div>
答案 0 :(得分:1)
您可以将Enumerable#find
与正则表达式匹配=~
结合使用,以获得所需的元素内容。
html.css(".reviewfold p").find { |e| e.text =~ /On Snow Feel/ }.text