nokogiri

Nokogiri gem installation error with spree

白昼怎懂夜的黑 提交于 2019-12-07 10:25:02
问题 I'm getting this error when I try to bundle install Bundler::GemspecError: Could not read gem at /home/theareba/.rvm/gems/ruby-2.0.0-p353/cache/nokogiri-1.6.1.gem. It may be corrupted. An error occurred while installing nokogiri (1.6.1), and Bundler cannot continue. Make sure that `gem install nokogiri -v '1.6.1'` succeeds before bundling. I've tried removing nokogiri in the cache and bundle installing again in vain. Here's my gemfile source 'https://rubygems.org' gem 'rails', '4.0.0' ruby "2

Why isn't Nokogiri installing?

懵懂的女人 提交于 2019-12-07 10:05:37
问题 I'm having trouble installing Nokogiri. When I run bundle install or gem install nokogiri the installation fails. The error I'm getting is: (Note: This failure is from using the installation command on nokogiri.org) Building native extensions. This could take a while... ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. /Users/roneesh/.rbenv/versions/1.9.3-p194/bin/ruby extconf.rb --with-xml2-include=/usr/local/Cellar/libxml2/2.9.1/include/libxml2 --with-xml2-lib=

How to change … (elipses) to … (three periods) in Ruby?

我怕爱的太早我们不能终老 提交于 2019-12-07 07:25:30
问题 I'm parsing this document using nokogiri . I found there are some … (elipses) characters in that page and can't be removed. I want to know how to use Ruby to replace all … (elipses) to ... (three periods). BTW, you can search this string to find all …s Specifies whether ALTER TABLE Edit: I added my program and the error message. # encoding: UTF-8 require 'nokogiri' require 'open-uri' require 'terminal-table' def change s {Nokogiri::HTML(" ").text => " ", Nokogiri::HTML(""").text => '"',

Append elements using Nokogiri::XML::Builder

人走茶凉 提交于 2019-12-07 05:37:13
问题 I have the following code: builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.myRoot do |xml| xml.oneChild xml.anotherChild end end Now I want to append a few child nodes to myRoot using the builder (in a second step, I know how to append them straight away). How can I do that? I've tried this: node = builder.doc.xpath('//myRoot/oneChild').first Nokogiri::XML::Builder.with(node) do |xml| xml.childOfOneChild 'Im a child of oneChild' end Which doesn't work. They won't stick

problems installing nokogiri gem on mac osx snow leopard with Ruby 2.0.0-p353

ぃ、小莉子 提交于 2019-12-07 05:02:25
问题 I have tried installing nokogiri on my rvm ruby 2.0.0-p353 using both homebrew and macports following instructions on the nokogiri installation page found here: http://nokogiri.org/tutorials/installing_nokogiri.html In both, I get exactly the same error message of bad file descriptor as shown below: → sudo gem install nokogiri Fetching: mini_portile-0.5.2.gem (100%) Successfully installed mini_portile-0.5.2 Fetching: nokogiri-1.6.1.gem (100%) Building native extensions. This could take a

How do I get the root element name of an XML document using Nokogiri?

試著忘記壹切 提交于 2019-12-07 03:47:53
问题 Using Nokogiri, I would like to determine the name of the root element. I thought that doing an XPath query for / would do the trick but apparently that node name is "document"? require 'nokogiri' doc = Nokogiri::XML('<foo>Hello</foo>') doc.xpath('/').first.name # => "document" doc.xpath('/foo').first.name # => "foo" How can I get the string "foo" for the root node name without knowing it ahead of time? 回答1: /* should work: require 'nokogiri' doc = Nokogiri::XML('<foo>Hello</foo>') doc.xpath(

How to scrape images from eBay and Amazon using XPath in Nokogiri from JSON

丶灬走出姿态 提交于 2019-12-07 02:37:52
问题 I'm trying to scrape images from websites using Nokogiri and XPath, so far with limited success. For a typical website whose HTML has img and src , I can use: tmp2 = Nokogiri::HTML(open(site_url)) tmp2.xpath("//img/@src").each do |src| ...do whatever end However, some sites like Amazon and eBay only trigger certain images with JavaScript. If I look at the code I can see the data in arrays. For example, from Amazon: <script type="text/javascript"> P.when('jQuery', 'cf').execute(function($, cf)

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

ぃ、小莉子 提交于 2019-12-07 00:57:37
问题 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

Require Nokogiri? No such file to load

吃可爱长大的小学妹 提交于 2019-12-07 00:28:27
问题 I'm trying to get started with using Nokogiri. I ran the command gem install nokogiri as an administrator in Windows 7 (64-Bit). The console said "successfully installed" and "1 gem installed". When I type in gem list --local OR gem q --local I see Nokogiri on the list of "Local Gems". However, when I try to use it via the require statement (in NetBeans), I get an error that there is "no such file to load". What am I doing wrong? I'm not a Ruby professional. This is also the first gem I've

What's the xpath syntax to get tag names?

流过昼夜 提交于 2019-12-06 19:06:32
问题 I'm using Nokogiri to parse a large XML file. Say I've got the following structure: <menagerie> <penguin>Pablo</penguin> <penguin>Mortimer</penguin> <bull>Ferdinand</bull> <aardvark>James Cornelius Madison Humphrey Zophar Handlebrush III</aardvark> </menagerie> I can count the non-penguins like this: xml.xpath('//menagerie//*[not(penguin)]').length // 2 But how do I get a list of the tags, like this? (The exact format isn't important; I just want to visually scan the non-penguins.) bull