Nokogiri 解析 ajax 加载的内容 [英] Nokogiri parse ajax-loaded content

查看:37
本文介绍了Nokogiri 解析 ajax 加载的内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

nokogiri 是否可以解析通过 ajax 加载的内容?如果不是,我将如何实现这一目标?

Is it possible for nokogiri to parse content loaded via ajax? If not how would I accomplish this?

推荐答案

Nokogiri 看不到 AJAX 内容,因为它不是 Javascript 解析器,因此无法解释它并执行所需的请求.

Nokogiri can't see the AJAX content because it isn't a Javascript parser, and, as a result, can't interpret it and do the needed request.

您想要的是 Watir 或它的衍生产品之一,具体取决于您的操作系统.他们将启动一个浏览器,该浏览器可以处理 Javascript 和由此产生的 AJAX 请求.

What you want is something like Watir, or one of its spinoffs, depending on your OS. They will launch a browser, which can process the Javascript and resulting AJAX request.

然后,您可以请求页面的内容,并使用 Nokogiri 解析 DOM.

Then, you can request the page's contents, and do your parsing of the DOM using Nokogiri.

对于通用示例来说,该过程过于具体,但是 Watir 平台页面 会将您指向浏览器支持的.示例 很容易弄清楚,因此您应该能够很好地将某些东西拼凑在一起.

The process is too specific for a generic example, but the Watir platform page will point you to the browsers supported. The examples are pretty easy is to figure out, so you should be able to piece something together nicely.

这篇关于Nokogiri 解析 ajax 加载的内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆