Nokogiri parse ajax-loaded content

[亡魂溺海] 提交于 2019-11-30 20:45:29

问题


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


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4341387/nokogiri-parse-ajax-loaded-content

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!