Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将文本输入Facebook';使用WWW::Mechanize::Firefox的事件表单?_Facebook_Perl_Www Mechanize Firefox - Fatal编程技术网

如何将文本输入Facebook';使用WWW::Mechanize::Firefox的事件表单?

如何将文本输入Facebook';使用WWW::Mechanize::Firefox的事件表单?,facebook,perl,www-mechanize-firefox,Facebook,Perl,Www Mechanize Firefox,Facebook没有用于向Facebook页面提交事件的API。所以我尝试将WWW::Mechanize::Firefox与这个脚本一起使用 use strict; use warnings; use feature qw(say); use WWW::Mechanize::Firefox; my $mech = WWW::Mechanize::Firefox->new(activate => 1); $mech->autoclose_tab(0); $mech->g

Facebook没有用于向Facebook页面提交事件的API。所以我尝试将WWW::Mechanize::Firefox与这个脚本一起使用

use strict;
use warnings;
use feature qw(say);
use WWW::Mechanize::Firefox;

my $mech = WWW::Mechanize::Firefox->new(activate => 1); 
$mech->autoclose_tab(0);
$mech->get('http://facebook.com');

if ($mech->title eq 'Facebook - Log In or Sign Up') {
  $mech->submit_form(
    with_fields => {
      email    => 'my@email.com',
      pass => 'my_password',
    }   
  );  
}
sleep(1);

$mech->get('https://www.facebook.com/PageName/events');
my $page_id = 777777777777777;

$mech->click({ synchronize => 0, xpath => '//a[text() = "Create Event"]' }, 10, 10);
sleep(3);

# selects all input fields and sets value to 'hello world'
# even though values are set, the fields remain blank
my @selectors = $mech->selector('input');
foreach my $selector (@selectors) {
  $mech->field( $selector, 'hello world');
}

# attempts to publish event, results in form errors because fields are blank
$mech->click({ synchronize => 0, xpath => '//button[text() = "Publish"]' });

# test to see if values are getting set.
# this returns 'hello world' as so values are getting set
say $mech->value($selectors[2]); 

# test to see if an input field can be selected with an xpath
# this works
$mech->click({ synchronize => 0, xpath => '//input[@placeholder="Include a place or address"]' });
Facebook生成的表单不便于在文本字段中输入数据。这些字段没有name属性,并且不能用css选择器区分(尽管可以用xpath选择),如最后一行所示

由于无法在字段中输入文本,Facebook会抛出错误,因为它认为字段为空,即使我使用
$mech->field
成功地将值输入字段

有没有办法将文本输入Facebook的表单以添加事件

更新 我在这方面取得了一些进展。我至少能够使用以下代码填写一些字段(
事件名称
位置
):

my $field = $mech->xpath( '//input[@placeholder="Include a place or address"]', one => 1);
$field->{value} = 'Room 315, City Hall';

$field = $mech->xpath( '//input[@placeholder="Add a short, clear name"]', one => 1);
$field->__click;
$field->{value} = "License committee meeting";
$mech->click({ synchronize => 0, xpath => '//button[text() = "Publish"]' }, 10, 10);
不幸的是,当我用以下代码单击“发布”按钮时:

my $field = $mech->xpath( '//input[@placeholder="Include a place or address"]', one => 1);
$field->{value} = 'Room 315, City Hall';

$field = $mech->xpath( '//input[@placeholder="Add a short, clear name"]', one => 1);
$field->__click;
$field->{value} = "License committee meeting";
$mech->click({ synchronize => 0, xpath => '//button[text() = "Publish"]' }, 10, 10);

将清除
事件名称
位置
文本字段,就像未输入任何内容一样。不确定此时还可以尝试什么。

没有API是有原因的。尝试自动化只会一次又一次地中断。