【问题标题】:Why CasperJS fills text input with [object Object]为什么 CasperJS 用 [object Object] 填充文本输入
【发布时间】:2016-10-05 11:05:21
【问题描述】:

我使用这段代码来填充文本输入

spooky.then([{question: question}, function(question) {
       this.fill('form[name="askmore"]', { questionask: question}, false);
 }]);

我在question 中有一个有效的刺痛。这是一个表单标记:

<form action="" name="askmore" id="askmore" method="post" onsubmit="return false;">
<table cellspacing="0" cellpadding="0" border="0">
<tbody><tr><td>
<input type="text" maxlength="400" name="questionask" id="questionask" style="padding-left:15px; margin-left:45px; font-size:20px; width:480px; height:43px; border:0px; background-color:#d4d4d4; ">
</td>
<td>
<img hspace="15" src="/images/button.png" id="send" style="cursor: pointer;">
</td></tr></tbody></table></form>

有人知道如何解决这个问题吗?我想我正在这样做,就像 CasperJS documentation 中的示例一样

【问题讨论】:

  • 将现有变量名作为对象构造的第一个操作数是危险的,而不是使用像{"question": question} 这样的引号。我知道您确实有一个有效的字符串,但是您是否仍然可以在创建的匿名函数中添加 console.log(question)console.log(questionask),并将显示的结果添加到您的问题中?
  • question 的初始值是多少?除了第二个之外,您是否尝试将 question 的所有外观重命名为 q

标签: javascript web-scraping phantomjs casperjs spookyjs


【解决方案1】:

不要将question 作为参数传递:

spooky.then([{question: question}, function() {
    this.fill('form[name="askmore"]', { questionask: question}, false);
}]);

【讨论】:

    猜你喜欢
    • 2015-07-21
    • 2019-05-18
    • 1970-01-01
    • 2014-10-24
    • 2016-06-16
    • 1970-01-01
    • 1970-01-01
    • 2015-07-03
    • 2013-10-20
    相关资源
    最近更新 更多