nokogiri

Nokogiri text node contents

与世无争的帅哥 提交于 2019-11-30 19:33:32
Is there any clean way to get the contents of text nodes with Nokogiri? Right now I'm using some_node.at_xpath( "//whatever" ).first.content which seems really verbose for just getting text. You want only the text? doc.search('//text()').map(&:text) Maybe you don't want all the whitespace and noise. If you want only the text nodes containing a word character, doc.search('//text()').map(&:text).delete_if{|x| x !~ /\w/} Edit: It appears you only wanted the text content of a single node: some_node.at_xpath( "//whatever" ).text Just look for text nodes: require 'nokogiri' doc = Nokogiri::HTML(<

Parse table using Nokogiri

大兔子大兔子 提交于 2019-11-30 18:06:30
问题 I would like to parse a table using Nokogiri. I'm doing it this way def parse_table_nokogiri(html) doc = Nokogiri::HTML(html) doc.search('table > tr').each do |row| row.search('td/font/text()').each do |col| p col.to_s end end end Some of the table that I have have rows like this: <tr> <td> Some text </td> </tr> ...and some have this. <tr> <td> <font> Some text </font> </td> </tr> My XPath expression works for the second scenario but not the first. Is there an XPath expression that I could

Nokogiri issues with Ruby on Rails

放肆的年华 提交于 2019-11-30 18:04:40
问题 I'm trying to install nokogiri on my machine but I am receiving the following error: Building native extensions. This could take a while... ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. current directory: /Users/username/.rbenv/versions/2.0.0-p481/lib/ruby/gems/2.0.0/gems/nokogiri-1.6.6.4/ext/nokogiri /Users/username/.rbenv/versions/2.0.0-p481/bin/ruby -r ./siteconf20151127-29540-11ahx4h.rb extconf.rb checking if the C compiler accepts ... *** extconf.rb

Nokogiri text node contents

谁说胖子不能爱 提交于 2019-11-30 16:58:56
问题 Is there any clean way to get the contents of text nodes with Nokogiri? Right now I'm using some_node.at_xpath( "//whatever" ).first.content which seems really verbose for just getting text. 回答1: You want only the text? doc.search('//text()').map(&:text) Maybe you don't want all the whitespace and noise. If you want only the text nodes containing a word character, doc.search('//text()').map(&:text).delete_if{|x| x !~ /\w/} Edit: It appears you only wanted the text content of a single node:

Can I delete some folders of nokogiri and capybara-webkit inside of my rvm gemset?

爷,独闯天下 提交于 2019-11-30 16:17:09
问题 I was using a disk analyzer and I noticed in my .rvm folder two gems, nokogiri and capybara-webkit , bigger than the usual: Checking inside of them I found that for nokogiri there is a temp folder and for capybara-webkit a source folder. My question is: Is it safe to delete these folders?(Yeah, I'm a greedy disk space saver) and why nokogiri is creating that temporary folder? Because I have another gemset (with a lower version of ruby and nokogiri) and there isn't creating that folder. 回答1:

Upgraded to ruby 1.9.2 and getting Segmentation Fault errors in nokogiri

て烟熏妆下的殇ゞ 提交于 2019-11-30 15:58:45
I decided to upgrade to 1.9.2 ruby yesterday and also installed rvm to do it. I ran a few recent files I had working previously on 1.8.7 but anything requiring nokogiri fails with the following errors. /Users/myusername/.rvm/gems/ruby-1.9.2-p0/gems/nokogiri-1.4.3.1/lib/nokogiri/nokogiri.bundle: [BUG] Segmentation fault ruby 1.8.7 (2009-06-12 patchlevel 174) [universal-darwin10.0] I am running nokogiri 1.4.3.1, ruby 1.9.2 on OSX Snow Leopard 10.6.4 If you get a Segmentation fault error from nokogiri, e.g., when you open your rails console, and you are using RVM and your ruby version is 1.9.2

Can I delete some folders of nokogiri and capybara-webkit inside of my rvm gemset?

99封情书 提交于 2019-11-30 15:55:47
I was using a disk analyzer and I noticed in my .rvm folder two gems, nokogiri and capybara-webkit , bigger than the usual: Checking inside of them I found that for nokogiri there is a temp folder and for capybara-webkit a source folder. My question is: Is it safe to delete these folders?(Yeah, I'm a greedy disk space saver) and why nokogiri is creating that temporary folder? Because I have another gemset (with a lower version of ruby and nokogiri) and there isn't creating that folder. Yes, you can remove the tmp directory. If you don't have a new-enough version of libxml2 or libxslt nokogiri

Clicking link with JavaScript in Mechanize

China☆狼群 提交于 2019-11-30 15:11:55
I have this: <a class="top_level_active" href="javascript:Submit('menu_home')">Account Summary</a> I want to click that link but I get an error when using link_to. I've tried: bot.click(page.link_with(:href => /menu_home/)) bot.click(page.link_with(:class => 'top_level_active')) bot.click(page.link_with(:href => /Account Summary/)) The error I get is: NoMethodError: undefined method `[]' for nil:NilClass That's a javascript link. Mechanize will not be able to click it, since it does not evaluate javascript. Sorry! Try to find out what happens in your browser when you click that link. Does it

&#146; is getting converted as “\\u0092” by nokogiri in ruby on rails

血红的双手。 提交于 2019-11-30 13:49:17
I have html page which has following line with some html entities like "&#146;". #Here I am not pasting whole html page content. just putting issue line only html_file = "<html>....<body><p>they&#146;re originally intended to describe the spread of of viral diseases, but they&#146;re nice analogies for how web/SN apps grow.<p> ...</body></html>" doc = Nokogiri::HTML(html) body = doc.xpath('//body') body_content = body[0].inner_html puts body_content Result: These terms come from the fields of medicine and biology they\u0092re originally intended to describe the spread of of viral diseases, but

Nokogiri error when running bundle install

浪尽此生 提交于 2019-11-30 12:38:09
问题 Trying to get a cloned Rails app running. When running bundle install I get this error: Using mini_portile (0.5.0) Installing nokogiri (1.6.0) Gem::InstallError: nokogiri requires Ruby version >= 1.9.2. An error occurred while installing nokogiri (1.6.0), and Bundler cannot continue. Make sure that `gem install nokogiri -v '1.6.0'` succeeds before bundling. But this is the output for rbenv version : › rbenv version 1.9.3-p429 (set by /Users/andrewguo/.rbenv/version) When running gem list I