How do I exclude certain text in an HTML p tag with Nokogiri using CSS selectors? -
i dealing html follows structure below. want ignore "random text" , want pull "text want" css selector.
the selector using right pulling of text:
variable = page.css('div.eight.columns.listingdetail p')
this html:
<div class="eight columns listingdetail"> <p> <span class="bold">random text</span> text want 1 </p> <p> <span class="bold">random text</span> <span class="bold price"> text want 2 <span></span> </span> </p> <p> <span class="bold">random text</span> </p> <p> <span class="bold">random text</span> text want 3 </p> </div>
so first p
, inside find last element , text:
puts page.css('div.eight.columns.listingdetail p').first.children.last.text
and find span
bold
, price
classes inside 1 of p
element , text:
puts page.css('div.eight.columns.listingdetail p span.bold.price').text
and last one:
puts doc.css('div.eight.columns.listingdetail p').last.children.last.text
Comments
Post a Comment