Tag: nokogiri

使用“sudo gem install nokogiri”在mac上安装nokogiri时出错

我试图安装nokogiri,因为它是启动rails所必需的 $ rails s /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/spec_set.rb:90:in `block in materialize’: Could not find nokogiri-1.5.5 in any of the sources (Bundler::GemNotFound) from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/spec_set.rb:83:in `map!’ from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/spec_set.rb:83:in `materialize’ from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/definition.rb:127:in `specs’ from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/bundler-1.1.5/lib/bundler/environment.rb:27:in `specs’ from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/rubygems-bundler-1.0.3/lib/rubygems-bundler/noexec.rb:41:in `candidate?’ from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/rubygems-bundler-1.0.3/lib/rubygems-bundler/noexec.rb:60:in `setup’ from /usr/local/rvm/gems/ruby-1.9.3-p194@global/gems/rubygems-bundler-1.0.3/lib/rubygems-bundler/noexec.rb:75:in `’ from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `require’ from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:60:in `rescue in require’ from /usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/site_ruby/1.9.1/rubygems/custom_require.rb:35:in `require’ from /usr/local/rvm/gems/ruby-1.9.3-p194/bin/ruby_noexec_wrapper:9:in `’ 但是,当我尝试使用该命令安装nokogiri时,它失败了 $ […]

如何遍历所有记录并将数据库值传递给变量?

我有两个表,“Que”和“Opts”。 我想遍历Que中的所有记录并将它们添加到变量rikt_nr , start_nr和end_nr ,因为它们将位于URL的末尾,如下所示: api.url.number=8-00001 如何让它迭代通过Que并将rikt_nr , start_nr和end_nr传递给其余的代码? Que表包含以下字段: create_table “ques”, force: true do |t| t.integer “rikt_nr” t.integer “start_nr” t.integer “end_nr” t.datetime “created_at” t.datetime “updated_at” end 和Opts有这些领域: create_table “opts”, force: true do |t| t.string “numbers” t.string “operator” t.datetime “created_at” t.datetime “updated_at” end 这是代码: Que.all.each do | que | url = “http://api.url.number=” que.rikt_nr = rikt_nr […]

如何将rails客户端转换为Hash

我像这样创建linkedin客户端。 client = LinkedIn::Client.new(“3333”, “rrrrrrr”) client.authorize_from_access(session[:atoken], session[:asecret]) 并获得这样的个人资料信息 @profile = client.profile 当我打印像“ puts client.profile ”这样的配置文件时,我得到以下输出 #<LinkedIn::Profile:0x4a77770 @doc=#<Nokogiri::XML::Document:0x253bb64 name="document" children=[#<Nokogiri::XML::Element:0x253b9fc name="pers on" children=[#, #<Nokogiri::XML::Element:0x253b84c name="first-name" children=[#]>, #, #<Nokogiri::XML::Element:0x253b57c name="last-name" children=[#]>, #, #<Nokogiri::XML::Element:0x253b2ac name="headline" children=[#]>, #, #<Nokogiri::XML: :Element:0x253afdc name="site-standard-profile-request" children=[#, #<Nokogiri::XML::Element:0x253ade 4 name="url" children=[#]>, #]>, #]>]>> 如何将其解析为hasmap或字符串? 请求帮助我,因为我是铁杆新手。

Nokogirigem安装错误与狂欢

我尝试捆绑安装时收到此错误 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. 我已经尝试在缓存中删除nokogiri并再次捆绑安装是徒劳的。 这是我的gem文件 source ‘https://rubygems.org’ gem ‘rails’, ‘4.0.0’ ruby “2.0.0” gem ‘spree_auth_devise’, github: ‘spree/spree_auth_devise’, branch: ‘2-1-stable’ gem ‘spree’, github: ‘spree/spree’, branch: ‘2-1-stable’ […]

使用Nokogiri查找包含的标记

我有一个像html元素: 我想通过id搜索这个元素,但似乎nokogiri被[]搞糊涂了。 我尝试着: doc.css(“#spam[#{eggs.id}]”) 但无济于事。

如何按属性值搜索

我有以下XML文档: foo1 foo2 data1 data2 foo3 foo4 我只需要抓取type = “foo:elementType1″的元素。 我尝试过这个,但是我得到了空洞的结果。 elems = doc.search(“//elements[@type=’foo:elementType1′]”) 我错过了什么?

安装nokogiri时出错(1.5.2)

当我尝试在rails项目上运行ruby时出现错误: An error occurred while installing nokogiri (1.5.2), and bundle cannot continue. Make sure that ‘gem install nokogiri -v 1.5.2 succeed before building. 我正在研究Ubuntu 10.10 我的同事在Windows / RVM上使用并没有这个问题。 编辑: gem_make.out /opt/bitnami/ruby/bin/ruby extconf.rb extconf.rb:10: Use RbConfig instead of obsolete and deprecated Config. checking for libxml/parser.h… yes checking for libxslt/xslt.h… yes checking for libexslt/exslt.h… yes checking for […]

如何使用nokogiri和rubyzip编辑docx

我正在使用rubyzip和nokogiri的组合来编辑.docx文件。 我正在使用rubyzip来解压缩.docx文件,然后使用nokogiri来解析和更改word / document.xml文件的主体但是有时候我最后关闭rubyzip它会破坏文件而我无法打开它或者修理它。 我在桌面上解压缩.docx文件并检查word / document.xml文件,并将内容更新为我更改为的内容,但所有其他文件都搞砸了。 有人可以帮我解决这个问题吗? 这是我的代码: require ‘rubygems’ require ‘zip/zip’ require ‘nokogiri’ zip = Zip::ZipFile.open(“test.docx”) doc = zip.find_entry(“word/document.xml”) xml = Nokogiri::XML.parse(doc.get_input_stream) wt = xml.root.xpath(“//w:t”, {“w” => “http://schemas.openxmlformats.org/wordprocessingml/2006/main”}).first wt.content = “New Text” zip.get_output_stream(“word/document.xml”) {|f| f << xml.to_s} zip.close

Nokogiri解析

我有一些XML: xml = <<-EOT Sport Mobile Flowers EOT 并希望解析它: id=[] text=[] doc = Nokogiri::XML(xml) doc.search(‘advcampaign_categories’).each do |cat| c = cat.at(‘category’) text << c.text id << c['id'] end h = Hash[text.zip id] 我的目标是获得像{sport:85, mobile:79..etc}这样的哈希值。 这段代码的问题是它只返回一个元素sport:85 。 有什么建议?

如何使用Nokogiri gem获取innerHtml

例如我有html: bla bla bla bla 我需要获得div.item的内部html: bla bla bla bla 我知道我可以使用: doc.css(“div.item:first”).text text方法返回没有任何html标签的干净文本 但是我应该怎样做才能获得div.item的内部html? 尝试: doc.css(“div.item:first”).html 但是没有用,文档也无济于事 有任何想法吗?