cfv1000 / phantomjs-cloud
PhantomJS Cloud API 封装器
1.0.3
2017-05-02 13:06 UTC
This package is auto-updated.
Last update: 2024-09-16 07:35:41 UTC
README
用于与 Phantom JS Cloud 交互的库
API 的示例和详细文档 https://phantomjscloud.com/docs/http-api/
简单示例
将网页写入 JPG 文件
include_once 'vendor/autoload.php'; $request = new \PhantomJS\PageRequest('http://www.example.com'); file_put_contents('example.com.jpg', $request->getResponse());
此示例不应用于生产环境。如果您需要向 API 执行高级 HTTP 请求,请使用专门的库。此库应仅用于编写您的请求
Guzzle 示例
include_once __DIR__ . '/vendor/autoload.php'; /** * write your phantom js request * @see https://phantomjscloud.com/docs/ */ $request = new \PhantomJS\PageRequest('http://www.example.com'); /** * Initialize Guzzle to perform HTTP requests * @see http://docs.guzzlephp.org/en/stable * The request url will be https://phantomjscloud.com/api/browser/v2/a-demo-key-with-low-quota-per-ip-address/?request={url:%22http://www.example.com%22} */ $client = new GuzzleHttp\Client(); $response = $client->get($request->getApiUrl() . '?request=' . $request->toJSON()); print $response->getBody();
TODO - 我们计划对这段代码进行哪些改进
- 有一个目录结构,允许您将 PhantomJS 类与辅助类分离
- 尽可能将公共参数迁移到受保护参数,并使用设置器和获取器。
- 查看类注释中的 TODO
- 在文档中添加示例