nokogiri

Undefined namespace prefix in Nokogiri and XPath

安稳与你 提交于 2019-11-28 13:32:08
I am trying to parse Youtube Gdata to see if video with given id exists. But there isn't normal tag but with namespace. On the link http://gdata.youtube.com/feeds/api/videos?q=KgfdlZuVz7I there is tag: <openSearch:totalResults>1</openSearch:totalResults> There is namespace openSearch: xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' but I dont know how to deal with it in Nokogiri and Ruby. Here is part of code: xmlfeed = Nokogiri::HTML(open("http://gdata.youtube.com/feeds/api/videos?q=#{video_id}")) xmlfeed.at_xpath("openSearch:totalResults") It gives error: Undefined namespace

How to save unescaped & in nokogiri xml?

故事扮演 提交于 2019-11-28 13:26:23
问题 How can I save & in the final xml file using nokogiri? My code is like: require 'rubygems' require 'nokogiri' file_name = "amp.xml" @doc = Nokogiri::XML('<project/>') arg = Nokogiri::XML::Node.new "arg", @doc arg['line'] = "how to save only &???" @doc.root.add_child(arg) File.open(file_name, 'w') {|f| f.write(@doc.to_xml) } and the output is like <?xml version="1.0"?> <project> <arg line="how to save only &???"/> </project> UPDATE Looks like I can use CDATA but not sure how to use it with

How to make Nokogiri transparently return un/encoded Html entities untouched?

谁说胖子不能爱 提交于 2019-11-28 11:32:06
How can I use Nokogiri with having html entities (like German umlauts) untouched? I.e.: # this is fine node = Nokogiri::HTML.fragment('<p>ö</p>') node.to_s # => '<p>ö</p>' # this is not node = Nokogiri::HTML.fragment('<p>ö</p>') node.to_s # => '<p>ö</p>' # this is what I need node = Nokogiri::HTML.fragment('<p>ö</p>') node.to_s # => '<p>ö</p>' I've tried to mess with both PARSE_OPTIONS and :save_with options but could not come up with a way to have Nokogiri just transparently behave like above. Any pointers? svenfuchs Ok, my question has been answered by Aaron via twitter / gist : require

Why does this Nokogiri XPath have a null return?

给你一囗甜甜゛ 提交于 2019-11-28 10:01:05
问题 I'm XPath-ing through a web page with NOKOGIRI. I'm familiar with XPath, but I cannot figure out why my XPath fails to pick up the specific row. See the ruby code. I used FireBug XML to validate my XPath, so I am 99% sure my XPath is correct. require 'nokogiri' require 'open-uri' @searchURL = 'http://www.umn.edu/lookup?UID=smit4562' @xpath = '//html/body/p/table/tbody/tr/td[2]/table/tbody/tr[2]' doc = Nokogiri::HTML(open(@searchURL)) puts 'row should be = Email Address: smit4562@umn.edu' puts

How can I create a nokogiri case insensitive Xpath selector?

|▌冷眼眸甩不掉的悲伤 提交于 2019-11-28 08:19:13
I'm using nokogiri to select the 'keywords' attribute like this: puts page.parser.xpath("//meta[@name='keywords']").to_html One of the pages I'm working with has the keywords label with a capital "K" which has motivated me to make the query case insensitive. <meta name="keywords"> AND <meta name="Keywords"> So, my question is: What is the best way to make a nokogiri selection case insensitive? EDIT Tomalak's suggestion below works great for this specific problem. I'd like to also use this example to help understand nokogiri better though and have a couple issues that I'm wondering about and

How to access attributes using Nokogiri

痴心易碎 提交于 2019-11-28 07:07:59
I have a simple task of accessing the values of some attributes. This is a simple script that uses Nokogiri::XML::Builder to create a simple XML doc. require 'nokogiri' builder = Nokogiri::XML::Builder.new(:encoding => 'UTF-8') do |xml| xml.Placement(:messageId => "392847-039820-938777", :system => "MOD", :version => "2.0") { xml.objects { xml.object(:myattribute => "99", :anotherattrib => "333") xml.nextobject_ '9387toot' xml.Entertainment "Last Man Standing" } } end puts builder.to_xml puts builder.root.attributes["messageId"] The results are: <?xml version="1.0" encoding="UTF-8"?>

How to load correct version of dynamic libraries and gems (libxml, Nokogiri) within a custom Rails engine gem?

风流意气都作罢 提交于 2019-11-28 05:45:00
问题 I am building a rails engine that uses the Nokogiri gem and I'm having trouble with my development setup in MacOS 10.7 and 10.8: In order for Nokogiri to work properly in my setup, I updated the libxml and libxslt libraries with: brew update brew install libxslt brew upgrade libxml2 gem uninstall nokogiri gem install nokogiri -- --with-xml2-include=/usr/local/Cellar/libxml2/2.9.0/include/libxml2 --with-xml2-lib=/usr/local/Cellar/libxml2/2.9.0/lib --with-xslt-dir=/usr/local/Cellar/libxslt/1.1

Read response with Nokogiri from a SOAP call with Savon

耗尽温柔 提交于 2019-11-28 04:18:41
问题 I have make a soap-call with Savon. This works fine and give the following response: <?xml version="1.0" encoding="utf-8"?> <soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http:// schemas.xmlsoap.org/soap/envelope/"> <soap:Body> <GetTop10Response xmlns="http://www.kirupafx.com"> <GetTop10Result> <string>string</string> <string>string</string> </GetTop10Result> </GetTop10Response> </soap:Body> </soap:Envelope> Now I

Error installing Nokogiri on bundle install but already installed

不羁岁月 提交于 2019-11-28 03:57:16
I'm having issues with bundling my Gemfile. I have Nokogiri installed already yet when I run bundle install it fails to load Nokogiri. Installing Nokogiri: gem install nokogiri Building native extensions. This could take a while... Successfully installed nokogiri-1.6.6.2 Parsing documentation for nokogiri-1.6.6.2 Done installing documentation for nokogiri after 2 seconds 1 gem installed Bundle install: bundle install sic@ANTHONYs-iMac Fetching gem metadata from https://rubygems.org/......... Fetching version metadata from https://rubygems.org/... Fetching dependency metadata from https:/

Error while installing Nokogiri (1.6.7) on El Capitan

烈酒焚心 提交于 2019-11-28 03:39:32
One of my developers have updated Nokogiri, and when pulling the updated Gemfile my bundle install fails. ➜ my-project git:(master) bundle install Fetching source index from https://rubygems.org/ Using rake 10.4.2 Using i18n 0.7.0 Using json 1.8.3 Using minitest 5.8.3 Using thread_safe 0.3.5 Using tzinfo 1.2.2 Using activesupport 4.2.3 Using builder 3.2.2 Using erubis 2.7.0 Using mini_portile2 2.0.0 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /Users/me/.rvm/rubies/ruby-2.1.2/bin/ruby extconf.rb --use-system-libraries checking if the C compiler accepts ... yes checking if