草庐IT

Nokogiri

全部标签

ruby-on-rails - 如何使用 Nokogiri 提取子文本?

我遇到了这个HTML:Howtoextractthis?Duisauteiruredolorinreprehenderitinvoluptatevelitessecillumdoloreeufugiatnullapariatur.Excepteursintoccaecatcupidatatnonproident,suntinculpaquiofficiadeseruntmollitanimidestlaborum.hello我想提取文本“Howtoextractthis?”。我该怎么做?我尝试使用以下代码,但附加了其他元素。我不确定如何排除它们,所以我只得到文本本身。doc=Nokog

ruby - 如何在 Nokogiri Ruby 中取消转义 HTML,所以 & 仍然是 & 而不是 &

我有一个标题doc.at('head/title').inner_html出现&它应该是&.我的原始文档是:Foo&Bar但结果如下:>>doc=Nokogiri::HTML.parse(file,nil,"UTF-8")>>doc.at('head/title')=>#>>>doc.at('head/title').inner_html=>"Foo&Bar"我不想像这样使用Iconv或CGI:>>require'cgi'>>CGI.unescapeHTML(doc.at('head/title').inner_html)=>"Foo&Bar"这很丑陋而且不方便。

ruby - Nokogiri html解析问题

我无法弄清楚为什么无法通过nokogiri正确解析关键字。在下面的例子中,我有一个href链接文本功能正常工作,但无法弄清楚如何提取关键字。这是我到目前为止的代码:.....doc=Nokogiri::HTML(open("http://www.cnn.com"))doc.xpath('//a/@href').eachdo|node|#doc.xpath("//meta[@name='Keywords']").eachdo|node|putsnode.text....这成功地呈现了页面中的所有ahref文本,但是当我尝试将它用于关键字时它没有显示任何内容。我已经尝试了几种变体,但没有成

ruby - 使用 Anemone 和 nokogiri 进行屏幕抓取需要帮助

我的起始页为http://www.example.com/startpage它有1220个列表,按标准方式分页,例如每页20个结果。我有代码可以解析结果的第一页,并跟踪在其url中包含“example_guide/paris_shops”的链接。然后我使用Nokogiri提取最后一页的特定数据。一切正常,20个结果写入文件。但是我似乎无法弄清楚如何让Anemone爬到下一页结果(http://www.example.com/startpage?page=2)然后继续解析该页面并然后是第3页(http://www.example.com/startpage?page=3)等等。所以我想问

ruby - 在 Centos 6.2 上使用 RVM 1.9.3 安装 nokogiri 时遇到问题

/usr/local/rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/mkmf.rb:381:in`try_do':Thecompilerfailedtogenerateanexecutablefile.(RuntimeError)Youhavetoinstalldevelopmenttoolsfirst.我已经在我的CentOS6.2服务器上使用RVM安装了ruby​​1.9.3。当我尝试运行geminstallnokogiri时,它会产生以下输出。我已经访问了nokogiri网站并使用yum安装了libxml2和libxslt依赖项:sudoyu

ruby - 使用 to_html 时如何避免在 Nokogiri 中漂亮地打印 HTML?

我将Nokogiri与RubyonRailsv2.3.8结合使用。有没有一种方法可以在使用to_html时避免Nokogiri中的pretty-print?我读到to_xml允许使用to_xml(:indent=>0)完成此操作,但这不适用于to_html。现在我正在使用gsub去除换行符。Nokogiri是否提供任何选项来执行此操作? 最佳答案 我使用.to_html(save_with:0)解决了这个问题?2.1.0:001>require'nokogiri'=>true2.1.0:002>doc=Nokogiri::HTML.

ruby - 为什么我无法加载 Nokogiri?

我通过运行安装了Nokogiri,没有任何问题:$sudogeminstallnokogiriBuildingnativeextensions.Thiscouldtakeawhile...Successfullyinstallednokogiri-1.5.91geminstalledInstallingridocumentationfornokogiri-1.5.9...InstallingRDocdocumentationfornokogiri-1.5.9...当我运行nokogiri.rb时:#!/usr/bin/ruby-wrequire'nokogiri'puts"Curren

Ruby 2.1 和 Nokogiri 安装错误?

我知道这个问题已经在这里“解决”了很多次,但我已经尝试了所有的解决方案,但仍然无法正常工作。这是我的错误:22-01-1417:57:56>geminstallnokogiriBuildingnativeextensions.Thiscouldtakeawhile...ERROR:Errorinstallingnokogiri:ERROR:Failedtobuildgemnativeextension./Users/josh/.rvm/rubies/ruby-2.1.0/bin/rubyextconf.rbExtractinglibxml2-2.8.0.tar.gzintotmp//p

ruby - 修改 html 节点内的文本 - nokogiri

假设我有以下HTML:Bullet1.Bullet2.Bullet3.Bullet4.Bullet5.我想用它做的是用它本身和尾随星号替换任何句点、问号或感叹号,这是在HTML节点内,然后转换回HTML。所以结果是:Bullet1.*Bullet2.*Bullet3.*Bullet4.*Bullet5.*我在IRB中一直在弄乱这个问题,但不太明白。这是我的代码:html="Bullet1.Bullet2.Bullet3.Bullet4.Bullet5."doc=Nokogiri::HTML::DocumentFragment.parse(html)doc.search("*").map

ruby - 在 Ruby 2.0.0p353(基于 rvm 的安装)下安装 Nokogiri 1.6.1 失败(OSX Mavericks)?

我尝试在Ruby和RVM下安装Nokogiri1.6.1,但失败并出现以下错误:Gem::Installer::ExtensionBuildError:ERROR:Failedtobuildgemnativeextension./Users/lmo0/.rvm/rubies/ruby-2.0.0-p353/bin/rubyextconf.rbExtractinglibxml2-2.8.0.tar.gzintotmp/x86_64-apple-darwin13.0.0/ports/libxml2/2.8.0...OKRunning'configure'forlibxml22.8.0...