Pritam Dey
2013-May-01 12:43 UTC
Need a help to get a good start with Nokogiri #css syntax.
Hi, I am learning "Nokogiri". But I am quite good Nokogiri''s #xpath technique.But wanted to learn also #css. So started to search online materials to see how other writes a code using CSS techniques. Doing so I got one interesting code as below: =======================================================#Google laptop search require "nokogiri" require "open-uri" result = open("http://www.google.co.in/search?q=laptop", "User-Agent" => "HTTP_USER_AGENT:Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US) AppleWebKit/534.13 (KHTML, like Gecko) Chrome/9.0.597.47 Safari/534.13").read() #puts result.inspect doc = Nokogiri::HTML(result) puts "result list" #puts doc puts doc.css("#resultStats").text puts "related searches" doc.css("#trev a").each do |x| puts "#{x.text} => #{x[:href]}" end puts "results" doc.css("#ires ol li").each do |x| node = x.at_css("div a") puts node[:href] puts node.text desc_node = x.at_css("div div.s") puts node.text end ======================================================= But I am not comfortable with some notation used here,so thought if anyone out there help me to redirect to a resource where I can learn such techniques. My hard confusion is with the below lines: ***** "#ires ol li" ***** - when to write this way? - what `#` stands for? Looking at the source page I saw `ires` is one id. -- when I need to use such `#` and when `.`? - Is there any other operators like `#` and `.` when using css? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Frederick Cheung
2013-May-01 14:16 UTC
Re: Need a help to get a good start with Nokogiri #css syntax.
On Wednesday, May 1, 2013 1:43:06 PM UTC+1, Ruby-Forum.com User wrote:> > > But I am not comfortable with some notation used here,so thought if > anyone out there help me to redirect to a resource where I can learn > such techniques. > >You need to read up on css selectors> My hard confusion is with the below lines: > > ***** "#ires ol li" ***** > > - when to write this way? > - what `#` stands for? Looking at the source page I saw `ires` is one > id. -- when I need to use such `#` and when `.`? >#foo finds an element with id foo whereas .foo finds an element with class foo. Which one to use depends on the markup.> - Is there any other operators like `#` and `.` when using css? > >Yes, there are a whole bunch, such as the pseudo selectors (:not, :nth-child), attribute selectors etc. https://developer.mozilla.org/en-US/docs/CSS/Getting_Started/Selectors has fairly exhaustive info Fred -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msg/rubyonrails-talk/-/4SyEsAD6UOsJ. For more options, visit https://groups.google.com/groups/opt_out.
Pritam Dey
2013-May-01 15:39 UTC
Re: Need a help to get a good start with Nokogiri #css syntax.
Frederick Cheung wrote in post #1107477:> On Wednesday, May 1, 2013 1:43:06 PM UTC+1, Ruby-Forum.com User wrote:> Yes, there are a whole bunch, such as the pseudo selectors (:not, > :nth-child), attribute selectors etc. > > https://developer.mozilla.org/en-US/docs/CSS/Getting_Started/Selectors > > has fairly exhaustive info@Fred Thank you very much! The source link you shared is exactly what I was looking for. For Nokogiri - I think only the selectors part would be great to read to get start Nokogiri right? -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Love U Ruby
2013-May-26 17:38 UTC
Re: Need a help to get a good start with Nokogiri #css syntax.
I am searching for a good example for the below method: Nokogiri::XML::Node#matches? (http://www.rubydoc.info/gems/nokogiri/frames) Nokogiri::XML::Node#fragment (http://www.rubydoc.info/gems/nokogiri/frames) Any one out there,ever used these 2 methods. I need an example against each,so your help will be much appreciated. Thanks -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/665ad0dbd9d3b5c84a8fb994493283a4%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
gerry.jenkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2013-May-27 17:47 UTC
Re: Need a help to get a good start with Nokogiri #css syntax.
check out this reference: http://www.w3schools.com/cssref/css_selectors.asp -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ab19f394-20c2-44d7-9689-b7a6384fd855%40googlegroups.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Love U Ruby
2013-May-27 18:42 UTC
Re: Need a help to get a good start with Nokogiri #css syntax.
gerry.jenkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote in post #1110301:> check out this reference: > > http://www.w3schools.com/cssref/css_selectors.aspNo Sir! I asked for the examples of the 2 methods,if any one ever used: Nokogiri::XML::Node#matches? Nokogiri::XML::Node#fragment -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/bf973f4ebe7e3797a2a1927e8c41f1a2%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.
Love U Ruby
2013-Jun-01 16:55 UTC
Re: Need a help to get a good start with Nokogiri #css syntax.
gerry.jenkins-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote in post #1110301:> check out this reference: > > http://www.w3schools.com/cssref/css_selectors.asphere is another link: http://reference.sitepoint.com/css/pseudoclass-firstoftype -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/18b321c8b74c35d73e1f3f4e79332fe2%40ruby-forum.com?hl=en-US. For more options, visit https://groups.google.com/groups/opt_out.