Tag: nokogiri

使用Nokogiri在XPath中逃脱单引号?

我有一个看起来像这样的XPath查询,包括单引号和双引号。 如何正确地转义撇号以使查询有效? 我试过了: “//li[text()=’Frank's car’]” 但它似乎不适合我。 有任何想法吗? “//li[text()=’Frank’s car’]”

是否有可能’卸载’(’un-require’)Ruby库?

我正在寻找加载一些库,让他们做一些工作,然后执行相反的require以避免以后的兼容性错误。 我不想转储到文件并重新启动shell,因为创建的对象(例如data )可以由我的其他库很好地处理,只是不存在我想要卸载的早期文件。 有人有任何建议或知道这是否可行? 2006年的一次谈话并没有得出多少结论,除了“看起来Webrick设法以某种方式做到这一点”。 有问题的库是Google_drive和Nokogiri (电子表格处理库Roo依赖于Google_drive进行在线电子表格读/写,如该链接所述)。

如何用Nokogiri解析连续标签?

我有这样的HTML代码: Label1 Value1 Label2 Value2 … 我的代码不起作用。 doc.css(“first”).each do |item| label = item.css(“dt”) value = item.css(“dd”) end 显示所有 标签第一,然后显示 标签,我需要“标签:值”

’ 在轨道上的ruby中由nokogiri转换为“\ u0092”

我有html页面,其中包含一些html实体,如“’”。 #Here I am not pasting whole html page content. just putting issue line only html_file = “….they’re originally intended to describe the spread of of viral diseases, but they’re nice analogies for how web/SN apps grow. …” doc = Nokogiri::HTML(html) body = doc.xpath(‘//body’) body_content = body[0].inner_html puts body_content 结果: These terms come from the […]

单击Mechanize中的JavaScript链接

我有这个: Account Summary 我想点击该链接但是在使用link_to时出错。 我试过了: 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/)) 我得到的错误是:NoMethodError:未定义的方法`[]’为nil:NilClass

用Nokogiri获取节点的兄弟姐妹

有没有办法在节点中找到特定值然后返回其所有兄弟值? 例如,我想找到包含ID 5678的id节点,然后获取电子邮件地址和与ID 5678相关的所有图像。 Nokogiri::XML.parse(File.open(‘info.xml’)) 这是一个示例XML文件。 1234 sdfsdf@sdasd.com images/1.jpg images/2.jpg images/3.jpg 5678 zzzz@zzz.com images/4.jpg images/5.jpg 9011 aaaa@aaa.com images/6.jpg images/7.jpg

使用nokogiri将嵌套哈希转换为XML

我有很多级别的嵌套哈希,如: { :foo => ‘bar’, :foo1 => { :foo2 => ‘bar2’, :foo3 => ‘bar3’, :foo4 => { :foo5 => ‘bar5’ }}} 我怎样才能将它们转换成这样的XML?: bar bar2 bar3 bar5 我已经尝试了xml.send方法,但它将上面嵌套的哈希转换为: bar

使用Mechanize和Nokogiri保存图像?

我正在使用Mechanize和Nokogiri来收集一些数据。 我需要保存每个请求随机生成的图片。 在我的尝试中,我被迫下载所有图片,但我唯一想要的是位于div#specific的图像。 此外,是否可以从中生成Base64数据,而无需保存或重新加载其来源? require ‘rubygems’ require ‘mechanize’ require ‘nokogiri’ a = Mechanize.new { |agent| agent.keep_alive = true agent.max_history = 0 } urls = Array.new() urls.push(‘http://www.domain.com’); urls.each {|url| page = a.get(url) doc = Nokogiri::HTML(page.body) if doc.at_css(‘#specific’) page.images.each do |img| img.fetch.save(‘picture.png’) end end }

错误 – “gem install rails” – 缺少libxml2

我一直在处理Rails安装说明( http://railsapps.github.io/installrubyonrails-mac.html ),一切顺利,直到我在New Rails Application下进入gem install rails部分。 当我跑的时候,我得到了libxml2。 这是日志: http : //codecascade.com/sIjhQ/raw 我有类似的问题安装nokogiri,我能够解决它的唯一方法是 gem install nokogiri — –use-system-libraries 我在OS X 10.10.2上。 我也安装了RubyMine,如果它可能相关的话。

升级到ruby 1.9.2并在nokogiri中获得Segmentation Fault错误

我决定昨天升级到1.9.2 ruby​​并安装了rvm来做到这一点。 我运行了一些我之前在1.8.7上工作的文件,但是任何需要nokogiri的文件都会因以下错误而失败。 /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] 我在OSX Snow Leopard 10.6.4上运行nokogiri 1.4.3.1,ruby 1.9.2