PHP-PHANTOMJS Chinese Document Usage sample collection __js

Source: Internet
Author: User

The

Php-phantomjs A collection of sample Chinese usage examples. Installation of those will not be said, are very simple things.
The following is an English version of the document API collation of the collection demo, according to their own selection of the corresponding content of the page can be

 <?php require ' vendor/autoload.php ';
Use jonnyw\phantomjs\client;//introduces the client/* Custom MODULE * */use Jonnyw\phantomjs\dependencyinjection\servicecontainer;
$location = '/path/to/your/script/directory ';//Custom module Folder $serviceContainer = Servicecontainer::getinstance (); $procedureLoader = $serviceContainer->get (' procedure_loader_factory ')->createprocedureloader ($location); See the page at the end of this article/* Normal instance/$client = Client::getinstance ()//instance/* Custom module */$client->setprocedure (' my_procedure ');/load a name of my _procedure.proc Custom JS module, see the end of this page $client->getprocedureloader ()->addloader ($procedureLoader);//Auto Load module/* Self-setting PHANTOMJS parameter/$client->getengine ()->addoption ('--load-images=true ');//phantomjs parameter, parameter address: http:// phantomjs.org/api/command-line.html $client->getengine ()->addoption ('--config=/path/to/config.json '); In addition to configuring commands individually, you can configure the JSON file for the command set configuration:: This page lists common configurations/* Debugging and Caching/$client->getengine ()->debug (true);/Allow or disable debugging $client-> GetLog (); When debugging is turned on, the output $client->getprocedurecompiler ()->clearcache ();//ClearCaching-the recommended purge $client->getprocedurecompiler ()->enablecache ()//Allow caching, recommended to open $client->getprocedurecompiler () ->disablecache ()//prohibit read cache/* Render and Request mode * * $link = ' http://jonnnnyw.github.io/php-phantomjs/4.0/3-usage/# On-load-finished ';//requested URL $client->islazy ();
If you want the client to wait for all resources to load, it's important to start settimeout and avoid polling pages waiting.
$request = $client->getmessagefactory ()->createrequest ();
$response = $client->getmessagefactory ()->createresponse ();
$request->seturl ($link); $request->setmethod (' get ');//Can be get| Post| options| head| delete| patch| Put $request->settimeout (5000);//Break Render $request->setdelay (5) over a specified time;/Set delay 5 seconds $request->setrequestdata ( Array (' param1 ' => ' Param 1 ', ' param2 ' => ' Param 2 '); Data sent at//post $request->addheader (' Custom_header_key ', ' Custom_header_value ')//Custom header information $client->send ($request, $response);//Send request//screenshot (image or PDF file)//$request-> Setrepeatingheader ('  

A. Common Command parameters:
1.--ignore-ssl-errors=[true|false] Ignores SSL errors, such as an expired or self-signed certificate error (default is False).
2.--load-images=[true|false] Loads all inline images (the default is true).
//Other rarely used, http://phantomjs.org/api/command-line.html

B. Custom module Usage:
Global_variables.partial allows any JavaScript variable to inject the top of the script.
Page_clip_rect.partial If the request is a screen capture, this defines the page clipping rectangle.
Page_custom_headers.partial set any custom headers on the Page object.
Page_on_error.partial The code that defines the error execution of the page.
Page_on_resource_received.partial defines the code that executes when a resource is received.
Page_on_resource_timeout.partial defines code that executes at a resource timeout.
Page_open.partial defines the code that executes when the page is opened.
Page_paper_size.partial If the request is a PDF output, this sets the paper size.
Page_settings.partial most clearly defines any page setting resource timeout value.
page_viewport_size.partial if defined in the request, set the viewport size.
Page_body_styles.partial sets the CSS style on the Body tab of the requested page.
Phantom_on_error.partial defines the code that executes in a PHANTOMJS error.
Procedure_capture.partial defines a request as the code that executes when the request is captured.
Procedure_default.partial defines code that executes as a default request.
Procedure_pdf.partial defines the code that the request executes when the PDF is requested.
The corresponding location when compiling: https://github.com/jonnnnyw/php-phantomjs/blob/master/src/JonnyW/PhantomJs/Resources/procedures/ Http_default.proc

In addition to the above default module, you can also customize a JS module.
First, create a. proc file with at least 755 permissions, such as/my_procedure (name at random, without a suffix when introduced above). Proc

. proc Sample Script
var page  = require (' webpage '). Create ();
Page.open (' {Input.geturl ()}} ', ' {{Input.getmethod ()}} ', ' {{input.getbody ()}} ', function (status) {
//your JS script 
  phantom.exit (1);//Exit
});
...

For more details, please refer to. http://jonnnnyw.github.io/php-phantomjs/4.0/4-custom-scripts/

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.