How can i find <li class="data-brand"> using nokogiri ?

4 views
Skip to first unread message

fugee ohu

unread,
Oct 16, 2018, 4:19:46 AM10/16/18
to Ruby on Rails: Talk
How can i find <li class="data-brand"> using nokogiri after running Nokogiri::HTML::Parse

Walter Lee Davis

unread,
Oct 16, 2018, 8:50:14 AM10/16/18
to rubyonra...@googlegroups.com

> On Oct 16, 2018, at 4:19 AM, fugee ohu <fuge...@gmail.com> wrote:
>
> How can i find <li class="data-brand"> using nokogiri after running Nokogiri::HTML::Parse

Two options, both using the CSS syntax:

@doc = Nokogiri::HTML.parse(...)

1. Get all of the elements that match that selector:

@doc.css('li.data-brand').each do |elm|
# do whatever with elm here
end

2. Get the first one in document source order:

elm = @doc.at_css('li.data-brand')

Walter

Reply all
Reply to author
Forward
0 new messages