开发者

Nokogiri parse ajax-loaded content

Is it possible for nokogiri to parse content loaded 开发者_StackOverflow社区via ajax? If not how would I accomplish this?


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.

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.

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

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.


Just post your content to the server with an AJAX call. Here a normal controller action can handle the response, including parsing with Nokogiri.

If you mean, 'Can I parse the result of an AJAX call with Nokogiri?', the answer is no. Nokogiri is server-side software and the results of an AJAX call arrive at the client.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜