簡體   English   中英

在模板引擎中渲染頁面后獲取頁面源?

[英]Getting source of a page after it's rendered in a templating engine?

因此,我在JS非常繁重的網站上進行了一些屏幕抓取。 它使用呈現所有內容的客戶端模板引擎。 我嘗試使用jQuery,並且可以在控制台中使用,但顯然不能在服務器(Nodejs)上使用。

我查看了一些用於Python和Java的庫,它們似乎能夠處理我想要的內容,但是我更喜歡與Node服務器配合使用的JS解決方案。

有什么方法可以使用Node獲取呈現頁面后的完整源代碼嗎?

我個人很喜歡PhantomJSSelenium ,它們確實做到了。

docs / examples應該開箱即用。

如果您想使用nodejs模塊,那么您可能對此感興趣:

https://github.com/sgentle/phantomjs-node

或這個:

https://github.com/alexscheelmeyer/node-phantom

我使用jsdom進行屏幕抓取 ,代碼在這里...

var jsdom = require( 'jsdom' );
jsdom.env( {
url: <give_url_of_page_u_want_to_scarpe>,
scripts: [ "http://code.jquery.com/jquery.js" ],
done: function( error, window ) {
  var $ = window.$;

  // required page is loaded in $....
  //you can write any javascript or jquery code get what ever you want

}
} );

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM