使用 WWW::Mechanize 更新 Facebook 状态

标签 facebook perl mechanize www-mechanize

我正在尝试使用 Mechanize 在 facebook 上更新状态。我可以使用脚本登录但无法更新。我验证了 id状态更新的表格是 "u_0_w" .
但是选择form_id方法说“ 没有ID 为“u_0_w 的表单” “”。
我的脚本是这样的:

use WWW::Mechanize;
use strict;
use warnings;
use Data::Dumper;
use HTTP::Cookies::Netscape;

my $cookiesfilename='/home/xxx/xxx/cookies.txt';
my $out;
my $mech = WWW::Mechanize->new( cookie_jar => HTTP::Cookies::Netscape->new( file => $cookiesfilename ) );
$mech->get("https://www.facebook.com/login.php");
my $response=$mech->submit_form(
    fields => {
        email => 'xxxx@xxxx.com',
        pass => 'xxxxx',
    }
);
#my $array=$mech->forms();
#$mech->get('/home.php');
print Dumper($mech->forms());
#$mech->form_id("u_0_w");
$mech->submit_form(
  fields => {
      xhpc_message_text=>'Why so serious'
    }
);
print $response->status_line;
open($out, ">",  "output_page.html") or die "Can't open output_page.html: $!";
print $out $response->decoded_content;

然后我尝试使用 Dumper 打印页面上的所有表单,输出为:
$VAR1 = bless( {
             'default_charset' => 'UTF-8',
             'enctype' => 'application/x-www-form-urlencoded',
             'accept_charset' => 'UNKNOWN',
             'action' => bless( do{\(my $o = 'https://www.facebook.com/search/web/direct_search.php')}, 'URI::https' ),
             'method' => 'GET',
             'attr' => {
                         'method' => 'get'
                       },
             'inputs' => [
                           bless( {
                                    'tabindex' => '-1',
                                    'value' => '1',
                                    'class' => '_42ft _42fu _4w98',
                                    'type' => 'submit'
                                  }, 'HTML::Form::SubmitInput' ),
                           bless( {
                                    '/' => '/',
                                    'autocomplete' => 'off',
                                    'tabindex' => '1',
                                    'name' => 'q',
                                    'aria-label' => 'Search Facebook',
                                    'value_name' => '',
                                    'class' => 'inputtext _586f',
                                    'type' => 'text',
                                    'id' => 'u_0_b',
                                    'role' => 'combobox',
                                    'placeholder' => 'Search Facebook'
                                  }, 'HTML::Form::TextInput' )
                         ]
           }, 'HTML::Form' );

这意味着它没有检测状态更新表单,它只检测 Facebook 搜索表单。
  • Mechanize 没有检测到所有表单元素的问题可能是什么?
  • 表单包含 <button type="submit"> . Mechanize 支持吗?
  • 最佳答案

    为什么必须为此使用 Mechanize?在 CPAN 上已经有一个可用的模块。

    看看WWW::Facebook::API .

    另见相关问题:How do I use Perl's WWW::Facebook::API to publish to a user's newsfeed?

    概要:

    use WWW::Facebook::API;
    my $facebook = WWW::Facebook::API->new(
        desktop => 0,
        api_key => $fb_api_key,
        secret => $fb_secret,
        session_key => $query->cookie($fb_api_key.'_session_key'),
        session_expires => $query->cookie($fb_api_key.'_expires'),
        session_uid => $query->cookie($fb_api_key.'_user')
    );
    
    my $response = $facebook->stream->publish(
     message => qq|Test status message|,
    );
    

    关于使用 WWW::Mechanize 更新 Facebook 状态,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31318234/

    相关文章:

    facebook - 我如何使用 selenium webdriver 发送 facebook 消息

    ios - Facebook iOS SDK - 获取好友列表

    mysql - 为什么我在 Perl Catalyst 的两个克隆实例之一上收到 DBIx "No such relationship"错误?

    ruby - 在 Windows 7 上为 Ruby 打开 SSL 错误

    ruby - 使用 Nokogiri 提取文本保留链接

    javascript - 如何检查是否有人在 Facebook 上分享了我的网页?

    ios - 验证 Facebook/Twitter 连接的最佳实践。 (防止逆向工程 key )

    perl - 如何在 Perl 中表示集合?

    regex - 在正则表达式匹配时打印匹配的行和行±1(1行)

    Python Mechanize 没有列出所有形式?