nokogiri

“Incompatible library version” on nokogiri

拟墨画扇 提交于 2020-01-07 09:04:55
问题 I've upgraded (apt-upgrade) my Ubuntu 14.03 server, including gitlab-ce. Now my Ruby (rack) websites don't seem to work anymore. I get the following error: incompatible library version - /home/taco/.rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.6.2/lib/nokogiri/nokogiri.so (LoadError) /home/taco/.rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.6.2/lib/nokogiri.rb:29:in `require' /home/taco/.rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.6.2/lib/nokogiri.rb:29:in `rescue in <top (required)>' /home/taco/.rvm/gems/ruby-2

“Incompatible library version” on nokogiri

ぃ、小莉子 提交于 2020-01-07 09:04:41
问题 I've upgraded (apt-upgrade) my Ubuntu 14.03 server, including gitlab-ce. Now my Ruby (rack) websites don't seem to work anymore. I get the following error: incompatible library version - /home/taco/.rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.6.2/lib/nokogiri/nokogiri.so (LoadError) /home/taco/.rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.6.2/lib/nokogiri.rb:29:in `require' /home/taco/.rvm/gems/ruby-2.1.2/gems/nokogiri-1.6.6.2/lib/nokogiri.rb:29:in `rescue in <top (required)>' /home/taco/.rvm/gems/ruby-2

How to understand this Arrays and loops in Ruby? [closed]

谁说胖子不能爱 提交于 2020-01-07 08:47:11
问题 It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 8 years ago . Regarding the following code: update: (thank you DGM and The Tin Man for recomendation on code and apneadiving for explanation.) ################# # get main page ################# rows = doc.xpath('//table[

Replace tags using Nokogiri - quicker way?

时光怂恿深爱的人放手 提交于 2020-01-07 05:07:05
问题 I have the following HTML in a variable named html_data where I wish to replace <img> tags with <a> tags and the src parameters of the "img" tags becomes href of the "a" tags. Existing HTML: <!DOCTYPE html> <html> <head> <title>Learning Nokogiri</title> </head> <body marginwidth="6"> <div valign="top"> <div class="some_class"> <div class="test"> <img src="apple.png" alt="Apple" height="42" width="42"> <div style="white-space: pre-wrap;"></div> </div> </div> </div> </body> </html> This is my

Parsing div elements with Nokogiri

假装没事ソ 提交于 2020-01-06 11:48:59
问题 The following code successfully extracts tid and term data: (answered generously by Uri Agassi) for i in (1..10) doc = Nokogiri::HTML(open("http://somewebsite.com/#{i}/")) tids = doc.xpath("//div[contains(concat(' ', @class, ' '),' thing ')]").collect {|node| node['data-thing-id']} terms = doc.xpath("//div[contains(concat(' ', @class, ' '),' col_a ')]").collect {|node| node.text.strip } tids.zip(terms).each do |tid, term| puts tid+" "+term end end from the following sample html: <div class=

Parsing div elements with Nokogiri

本小妞迷上赌 提交于 2020-01-06 11:48:10
问题 The following code successfully extracts tid and term data: (answered generously by Uri Agassi) for i in (1..10) doc = Nokogiri::HTML(open("http://somewebsite.com/#{i}/")) tids = doc.xpath("//div[contains(concat(' ', @class, ' '),' thing ')]").collect {|node| node['data-thing-id']} terms = doc.xpath("//div[contains(concat(' ', @class, ' '),' col_a ')]").collect {|node| node.text.strip } tids.zip(terms).each do |tid, term| puts tid+" "+term end end from the following sample html: <div class=

Getting, visiting and limiting the number of links using Nokogiri and Mechanize?

╄→尐↘猪︶ㄣ 提交于 2020-01-06 08:18:13
问题 I am trying to scrape the five latest stories from CNN.com and retrieve their links along with the first paragraph of each story. I have this simple script: url = "http://edition.cnn.com/?refresh=1" agent = Mechanize.new agent.get("http://edition.cnn.com/?refresh=1").search("//div[@id='cnn_maintt2bul']/div/div/ul/li[count(*)=3]/a").each do |headline| article = headline.text link = URI.join(url, headline[:href]).to_s page = headline.click(link) paragraph1 = page.at_css(".adtag15090+ p").text

Use XPath to select root and children matching expression

ぐ巨炮叔叔 提交于 2020-01-06 02:27:33
问题 I'm using Nokogiri to parse some XML that looks kind of like: <item name="item one"> <other name="other name"/> <third /> </item> <item name="item two"> <other /> <third /> </item> I'm parsing over the items using Nokogiri like so: xmldoc.xpath("//item").each do |node| node.xpath("//*[@name]") # Gives me *all* elements in the doc node.xpath(".//*[@name]") # Gives me child elements of the item end What expression can I use to get [item, other] from the first node as I iterate through? 回答1: The

Unable to install Nokogiri

ε祈祈猫儿з 提交于 2020-01-05 08:11:45
问题 When I run sudo gem install nokogiri on Ubuntu 12.1, I'm returned with this. What's wrong and how do I fix it? jason@jason:~/ror/clss$ sudo gem install nokogiri Building native extensions. This could take a while... ERROR: Error installing nokogiri: ERROR: Failed to build gem native extension. /usr/bin/ruby1.9.1 extconf.rb /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require': cannot load such file -- mkmf (LoadError) from /usr/lib/ruby/1.9.1/rubygems/custom_require.rb:36:in `require

How do you know when to use an XML parser and when to use ActiveResource?

流过昼夜 提交于 2020-01-05 03:20:28
问题 I tried using ActiveResource to parse a web service that was more like a HTML document and I kept getting a 404 error. Do I need to use an XML parser for this task instead of ActiveResource? My guess is that ActiveResource is only useful if you are consuming data from another Rails app and the XML data is easily translatable to a Rails model. For example, if the web service is more wide-ranging XML like a HTML document or an RSS feed, you want to use a parser like hpricot or nokogiri. Is this