ruby - how to use nokogiri methods .xpath & .at_xpath -


I am learning to use nogogiri and I have some questions depending on the code given below

  'rubygems' requires' mechanize' post_agent = WWW :: mechanize.new post_page = post_agent.get ('http://www.vbulletin.org/forum/showthread.php?t=230708 ') "\" Minor path with taba gives zero "post_page.parser.xpath (' / html / body / div / div / div / div / div / table / tbody / tr / td / div [2] ') Xpath ('text') ._to_s.strip.inspect says "\ n.at_xpath returns an empty string" post_page.parser.at_xpath ("// div [@ id = 'posts'] / Div / table / tr / td / div [2] "). At_xpath ('Text ()'). To_s.strip.inspect "\ ntwo lines place with the solution .at_xpath returns an empty string" line = post_page.parser.xpath ("// div [@ id = 'posts'] / Div / table / tr / td / div [2] ") rows [0] .at_xpath ('text ()'). To_s.strip.inspect puts" two lines working code "lines = post_pages is. Parser.xpath ("// div [@ id = 'posts'] / div / table / tr / td / div [2]") enters lines [0] .xpath ('text ()'). "None ine working code" post_page.parser.xpath ("// div [@ id = 'posts'] / div / table / tr / td / div [2]"] [0] .xpath ( 'Text ()') .to_s.strip "\ nanother one line code" puts post_page.parser.at_xpath ("// div [@ id = 'posts'] / div / table / tr / td / div [2] "). Xpath ('(html / body / div / div / div / div / div / div "(" (html / body / div / div / div / div / div / table / tr / td / div [edit] "(" ] "[0] .xpath ('text'). To_s.strip  
  • Is it better to use it in // or / xpath? Use of the Apufixel // is not such a good thing
  • I had to remove someone from the xpath of any work, otherwise I got 'zero' result. How to remove an element from things to work things Can I go?
  • Do not use full xpath Is it possible to use XP twice to remove data?
  • Why can not I .at_xpath work to remove the data? It works well, what's the difference?

  1. // every node Means, therefore, more expensive than /
  2. you can use * as placeholder.
  3. < Li> No, if you can create XPath query, then it Call on NOIDIGURI text method on the node
  4. Surely you can see and an example of my benchmark file at_xpath

I've found that you often use the text () expression, it is not necessary to use nocogiri, you can retrieve the node. , Then call the text method on the node. It is very less expensive.

Also keep in mind that the nasogene supports the CSS selectors. If you are working with HTML pages then they can be easy.


Comments

Popular posts from this blog

oracle - The fastest way to check if some records in a database table? -

php - multilevel menu with multilevel array -

jQuery UI: Datepicker month format -