小编Vit*_*lii的帖子

Phantomjs Function.prototype.bind

对,我知道.Phantomjs不支持函数绑定.但也许我可以使用其他东西,或者说不page.open使用bind?它似乎没问题,但有些网站会返回错误

TypeError: 'undefined' is not a function (evaluating 'b.bind(a)')
Run Code Online (Sandbox Code Playgroud)

之后我写了一个简单的脚本,它只打开一个页面:

var address = phantom.args[0];
if(!address) phantom.exit(1);

page = require("webpage").create();

page.open(address, function(status){
setInterval(
   function () {

   console.log(
       page.evaluate(function() {
            return document.body.innerHTML.length;
       })
   )}, 200)
})
Run Code Online (Sandbox Code Playgroud)

但错误仍然存​​在.错误不是主要问题,但问题是获取页面内容,因为错误页面内容未加载后...

所以,我需要帮助.

PS问题网站是http://vkrushelnytskiy.wix.com/aaaa

javascript phantomjs

6
推荐指数
2
解决办法
4072
查看次数

使用ScriptEngine从String评估数学公式

这是我的代码:

double value = 2.55;
String formule = "x+x";
Run Code Online (Sandbox Code Playgroud)

我想将句子中的x变量替换为value变量,所以我的下一个代码是:

formule = formule.replace("x", String.valueOf(value));
System.out.println(formule);
Run Code Online (Sandbox Code Playgroud)

我已经0.0+0.0回到了终点站.


这是我的代码,其中x - > 0.0永远:

protected double Formule(Double Value) throws ScriptException
{
    String ValueString = Value.toString();
    ScriptEngineManager factory = new ScriptEngineManager();
    ScriptEngine engine = factory.getEngineByName("JavaScript");
    Double source = null;
    formule = formule.replace("sin", "Math.sin").
         replace("cos", "Math.cos").
         replace("tan", "Math.tan").
         replace("sqrt", "Math.sqrt").
         replace("sqr", "Math.pow").
         replace("log", "Math.log").
         replace("x", ValueString);
    try {
        source = (Double)engine.eval(formule);
    } catch(Exception exc) {
        JOptionPane.showMessageDialog(null, "Invalid input", "Error", JOptionPane.ERROR_MESSAGE);
    }
    this.repaint(); …
Run Code Online (Sandbox Code Playgroud)

java string

-1
推荐指数
1
解决办法
2786
查看次数

标签 统计

java ×1

javascript ×1

phantomjs ×1

string ×1