Phantomjs-plaintext-property

提供:Dev Guides
移動先:案内検索

PhantomJS-プレーンテキストプロパティ

*plainText* プロパティは、htmlタグのないプレーンテキストとしてWebページのコンテンツを返します。

構文

その構文は次のとおりです-

wpage.plainText

*plainText* プロパティの使用方法を理解するための例を見てみましょう。
var wpage = require('webpage').create();
wpage.open('http://localhost/tasks/al', function (status) {
   console.log(wpage.plainText);
   phantom.exit();
});

al

<html>
   <head></head>

   <body name = "a">
      <script type = "text/javascript">
         console.log('welcome to cookie example');
         document.cookie = "username = Roy; expires = Thu, 22 Dec 2017 12:00:00 UTC";

         window.onload =  function() {
            console.log("page is loaded");
         }
      </script>

      <h1>This is a test page</h1>
      <h1>This is a test page</h1>
      <h1>This is a test page</h1>
      <h1>This is a test page</h1>
      <h1>This is a test page</h1>
      <h1>This is a test page</h1>
      <h1>This is a test page</h1>
      <h1>This is a test page</h1>
      <h1>This is a test page</h1>
   </body>

</html>

上記のプログラムは、次の output を生成します。

This is a test page

This is a test page

This is a test page

This is a test page

This is a test page

This is a test page

This is a test page

This is a test page

This is a test page

plainTextプロパティは、スクリプトタグやhtmlタグなしでコンテンツを返すだけです。