使用CasperJS/Javascript提交表单?
以下是我的代码片段:使用CasperJS/Javascript提交表单?,javascript,css-selectors,casperjs,reddit,Javascript,Css Selectors,Casperjs,Reddit,以下是我的代码片段: this.sendKeys('.usertext.cloneable > div > div.md > textarea', "Message"); //... this.evaluate(function(){ var entry = document.getElementsByClassName("usertext cloneable")[0].id; document.getElementById(entry).removeA
this.sendKeys('.usertext.cloneable > div > div.md > textarea', "Message");
//...
this.evaluate(function(){
var entry = document.getElementsByClassName("usertext cloneable")[0].id;
document.getElementById(entry).removeAttribute("action")
document.querySelector('#'+entry).submit()
})
此代码应该在使用sendKeys
填写表单后提交在网站(Reddit.com)上找到的表单。它完成了文本框的填写(我可以通过casper.capture
看到屏幕截图),但没有提交文本。我最初认为这是因为CSS选择器有问题,但我不再确定。由于action='#'
属性,Casper似乎没有发送表单,因此在提交表单之前将其删除。我不知道下一步该怎么办
及表格:
<form action="#" class="usertext cloneable" onsubmit="return post_form(this, 'comment')" id="form-t3_3gp8yji5i">
<input type="hidden" name="thing_id" value="t3_3gp8yj">
<div class="usertext-edit md-container" style="">
<div class="md">
<textarea rows="1" cols="1" name="text" class=""></textarea>
</div>
<div class="bottom-area">
<span class="help-toggle toggle" style="">
<a class="option active " href="#" tabindex="100" onclick="return toggle(this, helpon, helpoff)">formatting help</a>
<a class="option " href="#">hide help</a>
</span>
<a href="/wiki/reddiquette" class="reddiquette" target="_blank" tabindex="100">reddiquette</a>
<span class="error TOO_LONG field-text" style="display:none"></span>
<span class="error RATELIMIT field-ratelimit" style="display:none"></span>
<span class="error NO_TEXT field-text" style="display:none"></span>
<span class="error TOO_OLD field-parent" style="display:none"></span>
<span class="error DELETED_COMMENT field-parent" style="display:none"></span>
<span class="error DELETED_LINK field-parent" style="display:none"></span>
<span class="error USER_BLOCKED field-parent" style="display:none"></span>
<div class="usertext-buttons">
<button type="submit" onclick="" class="save">save</button>
<button type="button" onclick="cancel_usertext(this)" class="cancel" style="display:none">cancel</button>
<span class="status"></span>
</div>
</div>
<div class="markhelp" style="display:none">
<p></p>
<p>reddit uses a slightly-customized version of <a href="http://daringfireball.net/projects/markdown/syntax">Markdown</a> for formatting. See below for some basics, or check <a href="/wiki/commenting">the commenting wiki page</a> for more detailed help and solutions to common issues.
</p>
拯救
取消
reddit使用稍微定制的版本进行格式化。请参阅下面的一些基础知识,或查看更多详细的帮助和常见问题的解决方案。
以下是报告的错误:
Console: Unsafe JavaScript attempt to access frame with URL https://www.reddit.com/ from frame with URL https://static.adzerk.net/reddit/ads.html?sr=-reddit.com,loggedin&bust2#https://www.reddit.com. Domains, protocols and ports must match.
Console: Unsafe JavaScript attempt to access frame with URL https://www.reddit.com/ from frame with URL https://static.adzerk.net/reddit/ads.html?sr=-reddit.com,loggedin&bust2#https://www.reddit.com. Domains, protocols and ports must match.
Console: Unsafe JavaScript attempt to access frame with URL https://www.reddit.com/r/Pokemon_adventures/comments/3gp8yj/test_post_please_ignore/?thing_id=t3_3gp8yj&text=%22jnjrkefejkn%22 from frame with URL https://static.adzerk.net/reddit/ads.html?sr=pokemon_adventures,loggedin&bust2#https://www.reddit.com. Domains, protocols and ports must match.
Console: Unsafe JavaScript attempt to access frame with URL https://www.reddit.com/r/Pokemon_adventures/comments/3gp8yj/test_post_please_ignore/?thing_id=t3_3gp8yj&text=%22jnjrkefejkn%22 from frame with URL https://static.adzerk.net/reddit/ads.html?sr=pokemon_adventures,loggedin&bust2#https://www.reddit.com. Domains, protocols and ports must match.
Console: Unsafe JavaScript attempt to access frame with URL https://www.reddit.com/r/Pokemon_adventures/comments/3gp8yj/test_post_please_ignore/?thing_id=t3_3gp8yj&text=Message from frame with URL https://static.adzerk.net/reddit/ads.html?sr=pokemon_adventures,loggedin&bust2#https://www.reddit.com. Domains, protocols and ports must match.
Console: Unsafe JavaScript attempt to access frame with URL https://www.reddit.com/r/Pokemon_adventures/comments/3gp8yj/test_post_please_ignore/?thing_id=t3_3gp8yj&text=Message from frame with URL https://static.adzerk.net/reddit/ads.html?sr=pokemon_adventures,loggedin&bust2#https://www.reddit.com. Domains, protocols and ports must match.
控制台:不安全的JavaScript试图使用URL访问帧https://www.reddit.com/ 从带有URL的框架https://static.adzerk.net/reddit/ads.html?sr=-reddit.com、loggedin&bust2#https://www.reddit.com. 域、协议和端口必须匹配。
控制台:不安全的JavaScript试图使用URL访问帧https://www.reddit.com/ 从带有URL的框架https://static.adzerk.net/reddit/ads.html?sr=-reddit.com、loggedin&bust2#https://www.reddit.com. 域、协议和端口必须匹配。
控制台:不安全的JavaScript试图使用URL访问帧https://www.reddit.com/r/Pokemon_adventures/comments/3gp8yj/test_post_please_ignore/?thing_id=t3_3gp8yj&text=%22jnjrkefejkn%22 从带有URL的框架https://static.adzerk.net/reddit/ads.html?sr=pokemon_adventures,loggedin&bust2#https://www.reddit.com. 域、协议和端口必须匹配。
控制台:不安全的JavaScript试图使用URL访问帧https://www.reddit.com/r/Pokemon_adventures/comments/3gp8yj/test_post_please_ignore/?thing_id=t3_3gp8yj&text=%22jnjrkefejkn%22 从带有URL的框架https://static.adzerk.net/reddit/ads.html?sr=pokemon_adventures,loggedin&bust2#https://www.reddit.com. 域、协议和端口必须匹配。
控制台:不安全的JavaScript试图使用URL访问帧https://www.reddit.com/r/Pokemon_adventures/comments/3gp8yj/test_post_please_ignore/?thing_id=t3_3gp8yj&text=Message 从带有URL的框架https://static.adzerk.net/reddit/ads.html?sr=pokemon_adventures,loggedin&bust2#https://www.reddit.com. 域、协议和端口必须匹配。
控制台:不安全的JavaScript试图使用URL访问帧https://www.reddit.com/r/Pokemon_adventures/comments/3gp8yj/test_post_please_ignore/?thing_id=t3_3gp8yj&text=Message 从带有URL的框架https://static.adzerk.net/reddit/ads.html?sr=pokemon_adventures,loggedin&bust2#https://www.reddit.com. 域、协议和端口必须匹配。
表单中的action=“#”
看起来可疑,因此我会在重试之前删除它
如果无法更改HTML,可以在提交表单之前使用casper.js将其删除。表单中的操作=“#”
看起来可疑,因此我会在重试之前将其删除
如果无法更改HTML,可以在提交表单之前使用casper.js将其删除。表单中的操作=“#”
看起来可疑,因此我会在重试之前将其删除
如果无法更改HTML,可以在提交表单之前使用casper.js将其删除。表单中的操作=“#”
看起来可疑,因此我会在重试之前将其删除
如果您无法更改HTML,可以在提交表单之前使用casper.js将其删除。由于您遇到的错误与表单提交无关,您可以尝试以下操作:
- 使用CasperJS工具提交表单。使用
而不是this.fill(".usertext.cloneable", {}, true);
this.evaluate(…)代码>
- 使用CasperJS工具单击按钮:
this.click(".usertext.cloneable button[type='submit']");
如果这没有帮助,那么您可以使用
--web security=false--ssl protocol=any--ignore ssl errors=true
命令行选项运行CasperJS,尝试同样的方法。由于您遇到的错误与表单提交无关,您可以尝试以下操作:
- 使用CasperJS工具提交表单。使用
而不是this.fill(".usertext.cloneable", {}, true);
this.evaluate(…)代码>
- 使用CasperJS工具单击按钮:
this.click(".usertext.cloneable button[type='submit']");
如果这没有帮助,那么您可以使用
--web security=false--ssl protocol=any--ignore ssl errors=true
命令行选项运行CasperJS,尝试同样的方法。由于您遇到的错误与表单提交无关,您可以尝试以下操作:
- 使用CasperJS工具提交表单。使用
而不是this.fill(".usertext.cloneable", {}, true);
this.evaluate(…)代码>
- 使用CasperJS工具单击按钮:
this.click(".usertext.cloneable button[type='submit']");
如果这没有帮助,那么您可以使用
--web security=false--ssl protocol=any--ignore ssl errors=true
命令行选项运行CasperJS,尝试同样的方法。由于您遇到的错误与表单提交无关,您可以尝试以下操作:
- 使用CasperJS工具提交表单。使用
而不是this.fill(".usertext.cloneable", {}, true);
this.evaluate(…)代码>
- 使用CasperJS工具单击按钮:
this.click(".usertext.cloneable button[type='submit']");
如果这没有帮助,那么您可以尝试同样的方法运行CasperJS,并使用
--web security=false--ssl protocol=any--ignore ssl错误