nokogiri

Why can't I load Nokogiri?

烈酒焚心 提交于 2019-12-05 05:20:29
I installed Nokogiri without any issues by running: $ sudo gem install nokogiri Building native extensions. This could take a while... Successfully installed nokogiri-1.5.9 1 gem installed Installing ri documentation for nokogiri-1.5.9... Installing RDoc documentation for nokogiri-1.5.9... When I run nokogiri.rb: #!/usr/bin/ruby -w require 'nokogiri' puts "Current directory is: #{ Dir.pwd }" Dir.chdir("/home/askar/xml_files1") do |dirname| puts "Now in: #{ Dir.pwd }" xml_files = Dir.glob("ShipmentRequest*.xml") if xml_files.empty? puts "#{ dirname } is empty." else xml_files.each do |file| doc

Cleaning HTML with Nokogiri (instead of Tidy)

做~自己de王妃 提交于 2019-12-05 04:35:44
The tidy gem is no longer maintained and has multiple memory leak issues. Some people suggested using Nokogiri. I'm currently cleaning the HTML using: Nokogiri::HTML::DocumentFragment.parse(html).to_html I've got two issues though: Nokogiri removes the DOCTYPE Is there an easy way to force the cleaned HTML to have a html and body tag? If you are processing a full document, you want: Nokogiri::HTML(html).to_html That will force html and body tags, and introduce or preserve the DOCTYPE : puts Nokogiri::HTML('<p>Hi!</p>').to_html #=> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" #

Best way to perform XSL transformation in Ruby (XSLT 2.0)

删除回忆录丶 提交于 2019-12-05 04:28:21
What would be the best and most efficient way to to perform XSL transformation in Ruby? I have tried Nokogiri, but no matter what I tried it always results in: compilation error: element stylesheet The stylesheet works perfectly in my XML editor. I'm using Ruby 1.9.3 on Linux. After poking around, I found out that Nokogiri does not support XSLT 2.0: Nokogiri uses libxml2, which only supports XPath 1.0/XSLT1.0 My stylesheet was written using XSLT 2.0 syntax. I updated the title of this question to reflect this. I wish Nokogiri responded to it in a more meaningful way. Why do you want to perform

Is it possible to parse a stylesheet with Nokogiri?

醉酒当歌 提交于 2019-12-05 03:56:51
I've spent my requisite two hours Googling this, and I can not find any good answers, so let's see if humans can beat Google computers. I want to parse a stylesheet in Ruby so that I can apply those styles to elements in my document (to make the styles inlined). So, I want to take something like <style> .mystyle { color:white; } </style> And be able to extract it into a Nokogiri object of some sort. The Nokogiri class "CSS::Parser" ( http://nokogiri.rubyforge.org/nokogiri/Nokogiri/CSS/Parser.html ) certainly has a promising name, but I can't find any documentation on what it is or how it works

Nokogiri in Ruby 2.0

柔情痞子 提交于 2019-12-05 02:54:37
问题 When I require 'nokogiri' in Ruby 2.0, it has a error `require': cannot load such file -- nokogiri/2.0/nokogiri (LoadError) Is nokogiri not supporting Ruby 2.0 yet? I can see nokogiri in gem list 回答1: Ruby 2.0 support is not yet available for Windows. Follow along here for updates: 回答2: Yes, it works fine: RUBY_VERSION # => "2.0.0" require 'nokogiri' doc = Nokogiri::HTML('<html><body><p>foo</p></body></html>') doc.at('p').text # => "foo" 回答3: Nokogiri now support Ruby 2.0, even on Windows,

Nokogiri won't let me bundle install in Rails

ε祈祈猫儿з 提交于 2019-12-05 01:26:48
I've seen this question asked and tried everything I've seen suggested. I got a new macbook and am looking to set up an existing app. When i clone the app, it will not bundle install and acts like Rails is not installed, even though it works in other directories. I tried removing version numbers from gemfile and deleting gemfile.lock. I tried bundle update. I'm on osx 10.9.4, rails 4.1.5 and ruby 2.1.1. the error I am getting: An error occurred while installing nokogiri (1.6.3.1), and Bundler cannot continue. Make sure that `gem install nokogiri -v '1.6.3.1'` succeeds before bundling. I have

How can I get Nokogiri to parse and return an XML document?

[亡魂溺海] 提交于 2019-12-05 00:46:01
问题 Here's a sample of some oddness: #!/usr/bin/ruby require 'rubygems' require 'open-uri' require 'nokogiri' print "without read: ", Nokogiri(open('http://weblog.rubyonrails.org/')).class, "\n" print "with read: ", Nokogiri(open('http://weblog.rubyonrails.org/').read).class, "\n" Running this returns: without read: Nokogiri::XML::Document with read: Nokogiri::HTML::Document Without the read returns XML, and with it is HTML? The web page is defined as "XHTML transitional", so at first I thought

Nokogiri Xpath to retrieve text after <BR> within <TD> and <SPAN>

血红的双手。 提交于 2019-12-04 20:29:34
I have the following html and like to know how to use xpath to retrieve all the info: - Name(first, last) - Nick Name - email - shipping address... Primarily, retrieve text after <BR> . Many Thanks in advance. <table> <tr> <td valign="top" width="50%" align="left"> <span>Buyer</span><br/>FirstName LastName<br/>NickName<br/>First.Last@SomeCompany.com</td> <tr><td valign="top" width="40%" align="left"> <span><span>Shipping address - </span><span>confirmed</span></span><br/>FirstName LastName<br/>Attn: FirstName<br/>1234 Main St.<br/>TheCity, TheState, 12345<br/>United States<br/></td> </tr><

Gem File won't update or install with bundler

淺唱寂寞╮ 提交于 2019-12-04 19:46:04
I'm working on Michael Hartl's RoR tutorials. I'm on chapter 3. Unfortunately, copy and pasting the gem files won't work for me, but I figured out which gem is the problem. It's the capybara gem. I've commented it out and continued the tutorial, but I'm at the point where I need to use the gem. Here is an example $bundle update giving me an error: $ bundle update Fetching gem metadata from https://rubygems.org/......... (Removed a bunch of text) Building nokogiri using system libraries. Gem::Installer::ExtensionBuildError: ERROR: Failed to build gem native extension. /Users/dbz/.rvm/rubies

Nokogiri XML import feed organisation?

南楼画角 提交于 2019-12-04 19:45:26
I have built a site that relies on an XML feed that I currently parse with Nokogiri. Everything works fine and dandy although I have all the code currently within my Admin controller so I can actually invoke the import via a URL i.e. /admin/import/ . I can't help but think that this doesn't belong in the controller. Is there a better way to do this, i.e. move the code into a stand alone import.rb file so it is only accessible from the console? If so where would I need to put this file, in the /lib/ directory? Here is a code snippet: class AdminController < ApplicationController def import f =