在领英上发表一篇文章

Casperjs To publish a post in linkedin

本文关键字:一篇 文章      更新时间:2023-09-26

我使用casperjs登录领英并发布帖子。

var casper = require('casper').create({
logLevel: "info",              // Only "info" level messages will be logged
verbose: true  ,               // log messages will be printed out to the console
 waitTimeout: 50000
});
casper.start('https://www.linkedin.com/uas/login', function() {
this.echo(this.getTitle());
});
casper.thenEvaluate(function(term){
document.querySelector('input[id="session_key-login"]').setAttribute('value',term);
},'username');
casper.thenEvaluate(function(term){
document.querySelector('input[id="session_password-login"]').setAttribute('value',term);
},'password');
casper.then(function(){
this.click('input[name="signin"]');
console.log("clicking..........");
this.capture("linkedin.png");
});
casper.waitForSelector('a.publish', function() {
this.click('a.publish');
});
casper.waitForSelector('article.stream-article ', function() {
this.fillSelectors('article.stream-article',{
    'textarea.title':'This is title',
},false);
this.capture('linked3.png');
this.capture('linked4.png');
});
casper.then(function(){
this.sendKeys('textarea.title',"casper.page.event.key.Tab");
this.capture('linkedin5.png');
});
casper.then(function(){
this.fillSelectors('iframe[id^="editor-textarea"]',{
    'p':'This is title',
},false);
});
casper.run();

我能够登录并键入帖子的标题,但我无法选择iframe并键入帖子的描述。有人知道怎么做吗?

您是否尝试使用这个casper方法withFrame()访问一个框架,关于最新版本。

  casper.open("http://www.example.com", function() {
    casper.withFrame('your-frame', function() {
      this.test.assertSelectorExists('#id-selector-inside-frame', 'Selector found');
    });
  });

文件在这里http://casperjs.readthedocs.org/en/latest/modules/casper.html withframe