nokogiri

Nokogiri displaying data in view

和自甴很熟 提交于 2019-12-11 08:54:32
问题 Trying to figure out how display the text and images I have scraped in my application/html. Here is my app/scrape2.rb file require 'nokogiri' require 'open-uri' url = "https://marketplace.asos.com/boutiques/independent-label" doc = Nokogiri::HTML(open(url)) label = doc.css('#boutiqueList') @label = label.css('#boutiqueList img').map { |l| p l.attr('src') } @title = label.css("#boutiqueList .notranslate").map { |o| p o.text } Here is the controller: class PagesController <

OS X 10.6 Installing Nokogiri

ⅰ亾dé卋堺 提交于 2019-12-11 08:06:25
问题 I am very new to OS X and I don't know anything about compiling, MacPorts, Homebrew, etc. All I want to do is install the Nokogiri gem on OS X. In Windows, it was as simple as: gem install nokogiri However, when I try this on OS X, I get the following message: Building native extensions. This could take a while... ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. /System/Library/Frameworks/Ruby.framework/Versions/1.8/usr/bin/ruby extconf.rb mkmf.rb can't find

Open iso-8859-1 encoded html with nokogiri messes up accents

杀马特。学长 韩版系。学妹 提交于 2019-12-11 08:02:34
问题 I'm trying to make some changes to an html page encoded with charset=iso-8859-1 doc = Nokogiri::HTML(open(html_file)) puts doc.to_html messes up all the accents in the page. So if I save it back it looks broken in the browser as well. I'm still on Rails 3.0.6... Any hints how to fix this problem? Here's one of the pages suffering from that for example: http://www.elmundo.es/accesible/elmundo/2012/03/07/solidaridad/1331108705.html I've asked also in Github but I have the feeling this will be

Cleaning XML document recursively from empty tags with Nokogiri?

南笙酒味 提交于 2019-12-11 07:59:42
问题 I have a nested XML document that looks like this: <?xml version="1.0"?> <phone> <name>test</name> <descr>description</descr> <empty/> <lines> <line>12345</line> <css/> </lines> </phone> I need to remove all empty XML nodes, like <empty/> and <css/> . I ended up with something like: doc = Nokogiri::XML::DocumentFragment.parse <<-EOXML <phone> <name>test</name> <descr>description</descr> <empty/> <lines> <line>12345</line> <css/> </lines> </phone> EOXML phone = doc.css("phone") phone.children

Is there some equivalent in Java to Ruby's Nokogiri::XML::EntityDecl?

微笑、不失礼 提交于 2019-12-11 06:37:14
问题 I have an issue where I need to prepend a DTD containing ENTITYs bracketed in the definition to an existing XML document. For example, working from the specification for MathML in DAISY at http://www.daisy.org/projects/mathml/mathml-in-daisy-spec.html, say I am given this XML by an outside source: <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE dtbook PUBLIC "-//NISO//DTD dtbook 2005-2//EN" "http://www.daisy.org/z3986/2005/dtbook-2005-2.dtd"> <dtbook xmlns="http://www.daisy.org/z3986/2005

How to downgrade libxml 2.7.8 to 2.7.6 in Ubuntu

限于喜欢 提交于 2019-12-11 06:25:56
问题 One of my Rubygem (Nokogiri) was bult against libXML 2.7.6, but once i upgraded libXML to version 2.7.8, my programs are giving errors. To make my programs working i need to do a lot of modifications and i don't want to do them. Can i downgrade libXML to 2.7.6 回答1: Did you try rebuilding Nokogiri to use the newer version of libxml? gem uninstall nokogiri gem install nokogiri should do it. If you installed Nokogiri using sudo originally you'll need to use it with the commands above too.

Use SLIM/HAML etc. in a Ruby script?

▼魔方 西西 提交于 2019-12-11 05:59:57
问题 I am currently making a script that analyses some genetic data and then produce the output on a coloured Word document. The script works, however, one method in the script is badly written, the method that creates the Word document. The method creating the document creates a standalone HTML file, which is then saved with a 'docx' extension, which allows me to give different parts of the document different styles. Below is the bare minimum to get this to work. It includes some sample input

Why do I get “undefined method `von=' for nil:NilClass”?

元气小坏坏 提交于 2019-12-11 05:47:45
问题 I wrote this little program: require 'open-uri' require 'nokogiri' class Kapitel attr_accessor :von, :bis, :bezeichnung end class SubKapitel attr_accessor :von, :bis, :bezeichnung end def parse_file doc = Nokogiri::XML(File.open("test.xml")) parse_xml(doc) end def parse_xml(doc) doc.root.elements.each do |node| parse_kapitel(node) end end def parse_kapitel(node) if node.node_name.eql? 'nummer' tmp_kapitel = Kapitel.new end if node.node_name.eql? 'gruppe' tmp_kapitel = SubKapitel.new end tmp

Sorting XPath results in the same order as multiple select parameters

这一生的挚爱 提交于 2019-12-11 05:38:13
问题 I have an XML document as follows: <objects> <object uid="0" /> <object uid="1" /> <object uid="2" /> </objects> I can select multiple elements using the following query: doc.xpath("//object[@uid=2 or @uid=0 or @uid=1]") But this returns the elements in the same order they're declared in the XML document (uid=0, uid=1, uid=2) and I want the results in the same order as I perform the XPath query (uid=2, uid=0, uid=1). I'm unsure if this is possible with XPath alone, and have looked into XSLT

How does one properly validate an xml file with a local dtd file using Nokogiri?

点点圈 提交于 2019-12-11 05:35:14
问题 I have a simple, valid DTD and a valid XML file that seems to conform to the DTD, but Nokogiri is generating a lot of validation output, meaning that the XML file fails the validation. The dtd file is: <!ELEMENT protocol (copyright?, description?, interface+)> <!ATTLIST protocol name CDATA #REQUIRED> <!ELEMENT copyright (#PCDATA)> <!ELEMENT interface (description?,(request|event|enum)+)> <!ATTLIST interface name CDATA #REQUIRED> <!ATTLIST interface version CDATA #REQUIRED> <!ELEMENT request