• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

cognitom/gulp-phantom: PhantomJS plugin for gulp

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(OpenSource Name):

cognitom/gulp-phantom

开源软件地址(OpenSource Url):

https://github.com/cognitom/gulp-phantom

开源编程语言(OpenSource Language):

CoffeeScript 66.0%

开源软件介绍(OpenSource Introduction):

gulp-phantom Build Status NPM version

A PhantomJS plugin for gulp. This plugin read the source from gulp.src as a script of PhantomJS, and record the output into the through object. So you can execute and convert multiple scripts into the texts. It's handy for testing or scraping webpages.

Install

brew install phantomjs
npm install gulp-phantom --save-dev

Usage

var gulp = require("gulp");
var phantom = require("gulp-phantom");

gulp.task('phantom', function(){
  gulp.src("./phantom/*.js")
    .pipe(phantom({
      ext: 'json'
    }))
    .pipe(gulp.dest("./data/"));
});

or write it in CoffeeScript. When using Coffee in PhantomJS, coffee() needed.

gulp = require 'gulp'
coffee = require 'gulp-coffee'
phantom = require 'phantom'

gulp.task 'phantom', ->
  gulp.src './phantom/*.coffee'
  .pipe coffee()
  .pipe phantom ext:'.json'
  .pipe gulp.dest './data/'

Example PhantomJS Script

The script like below can get the JSON from the table on the website.

page = (require 'webpage').create()

page.open "http://examplesite.com/", ->
  result = page.evaluate ->
    for row in $('table#ex > tbody').children()
      for cell in $(row).children()
        $(cell).text()
  console.log JSON.stringify result
  phantom.exit()

Example Dir Structure

  • /
    • data/
      • schedule-table.json (generated)
    • phantom/
      • schedule-table.coffee
    • gulpfile.js
    • package.json

Options

You can change the extension easily by ext option.

  • ext: '.txt'
  • trim: false Trim newline at the end of file: true or false (default)

Other options are the same as what's supported by phantomjs.

  • cookiesFile: <val> Sets the file name to store the persistent cookies
  • config: <val> Specifies JSON-formatted configuration file
  • debug: <val> Prints additional warning and debug message: 'true' or 'false' (default)
  • diskCache: <val> Enables disk cache: 'true' or 'false' (default)
  • ignoreSslErrors: <val> Ignores SSL errors (expired/self-signed certificate errors): 'true' or 'false' (default)
  • loadImages: <val> Loads all inlined images: 'true' (default) or 'false'
  • localStoragePath: <val> Specifies the location for offline local storage
  • localStorageQuota: <val> Sets the maximum size of the offline local storage (in KB)
  • localToRemoteUrlAccess: <val> Allows local content to access remote URL: 'true' or 'false' (default)
  • maxDiskCacheSize: <val> Limits the size of the disk cache (in KB)
  • outputEncoding: <val> Sets the encoding for the terminal output, default is 'utf8'
  • remoteDebuggerPort: <val> Starts the script in a debug harness and listens on the specified port
  • remoteDebuggerAutorun: <val> Runs the script in the debugger immediately: 'true' or 'false' (default)
  • proxy: <val> Sets the proxy server, e.g. '--proxy=http://proxy.company.com:8080'
  • proxyAuth: <val> Provides authentication information for the proxy, e.g. ''-proxy-auth=username:password'
  • proxyType: <val> Specifies the proxy type, 'http' (default), 'none' (disable completely), or 'socks5'
  • scriptEncoding: <val> Sets the encoding used for the starting script, default is 'utf8'
  • webSecurity: <val> Enables web security, 'true' (default) or 'false'
  • sslProtocol: <val> Sets the SSL protocol (supported protocols: 'SSLv3' (default), 'SSLv2', 'TLSv1', 'any')
  • sslCertificatesPath: <val> Sets the location for custom CA certificates (if none set, uses system default)
  • help Shows this message and quits
  • version Prints out PhantomJS version

Related

  • node-phantom is another approach for PhantomJS. You can send commands from Node to PhantomJS via sockets.
  • gulp-spawn is recommended plugin for calling shell from gulp. But it needs some tricks to use with PhantomJS.



鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap