将参数从php传递到casperjs/phantomjs

编程入门 行业动态 更新时间:2024-10-28 06:32:21
本文介绍了将参数从php传递到casperjs/phantomjs的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我回答了我自己的问题,请参见下面的编辑.

I answered my own question, see edit below.

原始: 我在我的Web服务器上安装了phantomjs和casperjs,它们都可以正常运行.我计划创建的脚本依赖于我网站上的用户输入,然后将其传递给casperjs脚本. 经过一番摆弄之后,我注意到我被困在用户输入的最基本任务上.如何将变量从php传递到casperjs?

ORIGINAL: I have phantomjs and casperjs installed on my web server and they both run fine. The script I am planning on creating relise on a user input from my website, which is then passed on to the casperjs script. After fiddling around a bit, I noticed that I am stuck on the very basic task of the user input. How would pass the variable from php to casperjs?

请注意,以下只是测试脚本.

Please note, the following are just test scripts.

我的php脚本

$user_input = $_POST['user_input']; putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs"); exec('/usr/local/bin/casperjs hello.js 2>&1',$output); print_r($output);

hello.js

var user_input = "example/"; var casper = require('casper').create({ verbose: true, logLevel: 'error', pageSettings: { loadImages: false, loadPlugins: false } }); casper.start(user_input, function() { this.echo(this.getTitle()); }); casper.run();

那么我该如何将$ user_input传递给hello.js.我的目标是用户可以输入一个网址,然后将该网址抓取.

So how would I pass the $user_input to the hello.js. My goal is that the user can input a url which is then being scraped.

推荐答案

我自己找到了答案.

似乎phantomjs和casperjs支持命令行参数 phantomjs/api /system/property/args.html

It seems phantomjs and casperjs support command line arguments phantomjs/api/system/property/args.html

我的脚本现在看起来像这样.

My script now looks like this.

test.php

$user_input = $_POST['user_input']; putenv("PHANTOMJS_EXECUTABLE=/usr/local/bin/phantomjs"); exec('/usr/local/bin/casperjs hello.js $user_input 2>&1',$output); print_r($output);

hello.js

var system = require('system'); var args = system.args; var address = args[4]; //In my case 4 was the argument for $user_input, yours might be different, depending on your server setup. var casper = require('casper').create({ verbose: true, logLevel: 'error', pageSettings: { loadImages: false, loadPlugins: false } }); casper.start(address, function() { this.echo(this.getTitle()); }); casper.run();

更多推荐

将参数从php传递到casperjs/phantomjs

本文发布于:2023-07-07 04:42:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1058910.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:参数   php   phantomjs   casperjs

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!