nokogiri

Getting the siblings of a node with Nokogiri

眉间皱痕 提交于 2019-12-19 02:43:45
问题 Is there a way to find a specific value in a node and then return all its sibling values? For example, I would like to find find the id node that contains ID 5678 and then get the email address and all images associated with ID 5678. Nokogiri::XML.parse(File.open('info.xml')) Here's a sample XML file. <xmlcontainer> <details> <id>1234</id> <email>sdfsdf@sdasd.com</email> <image>images/1.jpg</image> <image>images/2.jpg</image> <image>images/3.jpg</image> </details> <details> <id>5678</id>

Upgraded to ruby 1.9.2 and getting Segmentation Fault errors in nokogiri

只谈情不闲聊 提交于 2019-12-18 17:11:11
问题 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 回答1: If you get a Segmentation fault error

Clicking link with JavaScript in Mechanize

纵饮孤独 提交于 2019-12-18 17:05:05
问题 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 回答1: That's a javascript link. Mechanize will not be able to click it, since it does not

What is a robust installation process for Nokogiri (on Ubuntu)?

让人想犯罪 __ 提交于 2019-12-18 12:36:13
问题 I tried to install Nokogiri on my Ubuntu 12.04 system, and got an error that said " libxslt is missing ", but the libxslt-dev and libxml2-dev are installed. Is there a robust installation process? How can I check the links to dependent libraries? I used RVM, and the RVM pkg is installed too. ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. /home/victor/.rvm/rubies/ruby-1.9.3-p125/bin/ruby extconf.rb checking for libxml/parser.h... yes checking for libxslt/xslt.h.

How do I use Nokogiri::XML::Reader to parse large XML files?

淺唱寂寞╮ 提交于 2019-12-18 12:23:27
问题 I'm trying to use Ruby's Nokogiri to parse large (1 GB or more) XML files. I'm testing code on a smaller file, containing only 4 records available here. I'm using Nokogiri version 1.5.0, Ruby 1.8.7 on Ubuntu 10.10. Since I don't understand SAX very well, I'm trying Nokogiri::XML::Reader to start. My first attempt, to retrieve the content of the PMID tag, looks like this: #!/usr/bin/ruby require "rubygems" require "nokogiri" file = ARGV[0] reader = Nokogiri::XML::Reader(File.open(file)) p = []

How to add child nodes in NodeSet using Nokogiri

帅比萌擦擦* 提交于 2019-12-18 11:59:16
问题 I am trying to add child nodes under a root node .. I tried out with below xml but this doesn't work. I am newbie to Ruby and Nokogiri builder = Nokogiri::XML::Builder.with(@doc) do |xml| nodes = Nokogiri::XML::NodeSet.new(@doc, []) [].each {|nodes_one_by_one| << nodes_one_by_one.Book << nodes_one_by_one.Pen } end I need to add nodes below a root node like this <Catalog> <Book>abc</Book> <Book_Author>Benjamin</Book_author> That works good for me .. but what i exactly need is to add these

How to install Nokogiri Gem for Windows

℡╲_俬逩灬. 提交于 2019-12-18 11:44:27
问题 I'm having this problem with nokogiri's gem: Could not open library 'C:\Ruby187\lib\ruby\gems\1.8\gems\nokogiri-1.4.6-x86-mingw32\ext\nokogiri\libxml2.dll' : unknown I read that I had to try the 1.5.0.beta3 version. However, when I run C:\Users\t3en4>gem install nokogiri --pre Fetching: nokogiri-1.5.0.beta.4.gem (100%) ERROR: Error installing nokogiri: The 'nokogiri' native gem requires installed build tools. Please update your PATH to include build tools or download the DevKit from 'http:/

How to convert Nokogiri Document object into JSON

纵然是瞬间 提交于 2019-12-18 11:08:50
问题 I have some parsed Nokogiri::XML::Document objects that I want to print as JSON. I can go the route of making it a string, parsing it into a hash, with active-record or Crack and then Hash.to_json; but that is both ugly and depending on way too manay libraries. Is there not a simpler way? As per request in the comment, for example the XML <root a="b"><a>b</a></root> could be represented as JSON: <root a="b"><a>b</a></root> #=> {"root":{"a":"b"}} <root foo="bar"><a>b</a></root> #=> {"root":{"a

extract links (URLs), with nokogiri in ruby, from a href html tags?

ぐ巨炮叔叔 提交于 2019-12-18 10:05:25
问题 I want to extract from a webpage all URLs how can I do that with nokogiri? example: <div class="heat"> <a href='http://example.org/site/1/'>site 1</a> <a href='http://example.org/site/2/'>site 2</a> <a href='http://example.org/site/3/'>site 3</a> </diV> result should be an list: l = [' http://example.org/site/1/ ', ' http://example.org/site/2/ ', ' http://example.org/site/3/ ' 回答1: You can do it like this: doc = Nokogiri::HTML.parse(<<-HTML_END) <div class="heat"> <a href='http://example.org

Nokogiri and Xpath: find all text between two tags

試著忘記壹切 提交于 2019-12-18 06:56:29
问题 I'm not sure if it's a matter of syntax or differences in versions but I can't seem to figure this out. I want to take data that is inside a (non-closing) td from the h2 tag to the h3 tag. Here is what the HTML would look like. <td valign="top" width="350"> <br><h2>NameIWant</h2><br> <br>Town<br> PhoneNumber<br> <a href="mailto:emailIwant@nowhere.com" class="links">emailIwant@nowhere.com</a> <br> <a href="http://websiteIwant.com" class="links">websiteIwant.com</a> <br><br> <br><img src=