Perl Facebook登录与Mechanize失败的cookie错误 [英] Perl Facebook Login with Mechanize failed cookies error

查看:303
本文介绍了Perl Facebook登录与Mechanize失败的cookie错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个脚本从网站上刮取我的分数。这个网站使用我的Facebook帐户登录。由于几天的脚本不再工作,我得到以下错误:

I have a script that scrapes my scores from an website. This website uses my Facebook account for logging in. Since a few days the script does not work anymore and I get the following error:


Cookie必需:
您的浏览器未启用Cookie。请在您的
浏览器偏好设置中启用Cookie以继续。

Cookies Required: Cookies are not enabled on your browser. Please enable cookies in your browser preferences to continue.

我在此论坛上搜索过,我发现了一个类似的问题:
我尝试了给定的解决方案,但它没有工作。

I searched on this forum and I found a similar problem: I tryed the given solution but it did not work.

我使用此插件从Google Chrome导出我的FaceBook登录cookies.txt。 https://chrome.google.com/webstore/detail/cookiestxt/njabckikapfpffapmjgojcnbfjonfjfg ?hl = en 并将cookies.txt保存在与脚本相同的文件夹中:

I have export my FaceBook login cookies.txt from Google Chrome with this plugin. https://chrome.google.com/webstore/detail/cookiestxt/njabckikapfpffapmjgojcnbfjonfjfg?hl=en and save the cookies.txt in the same folder as the script:

use WWW::Mechanize;
use use HTTP::Cookies::Netscape;
my $mech = WWW::Mechanize->new( cookie_jar => HTTP::Cookies::Netscape->new( file => $cookies.txt ) );
$mech->agent_alias('Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0');
$mech->get("https://www.facebook.com/login.php");
$mech->submit_form(
fields => {
    email => '<my email here>',
    pass => '<my password here>',
   }
);

open($out, ">",  "output_page.html") or die "Can't open output_page.html: $!";
print $out $mech->content;    

在脚本中我使用代理:Firefox,但cookie是从Chrome导出的,这可能是一个问题?我尝试了不同的方法和语言Python和perl。

In the script I use Agent: Firefox but the cookies are exported from Chrome, is this maybe an issue? I have tryed different methods and languages Python and perl.

推荐答案


请在脚本顶部使用strict 和使用警告

在您的脚本中此行有问题

In your script This line is problem

my $ mech = WWW :: Mechanize-> new(cookie_jar => HTTP :: Cookies :: Netscape-> new(file => $ cookies.txt));

将其更改为

my $cookies= 'cookies.txt'; #your cookies file path here
my $mech = WWW::Mechanize->new( cookie_jar => HTTP::Cookies::Netscape->new( file => $cookies ) );

更正您的脚本的所有错误:

Correcting all errors your script should be:

#!/usr/bin/perl
use strict;
use warnings;
use WWW::Mechanize;
use HTTP::Cookies::Netscape; #you were using two times use
my $cookies='your cookies file path';
my $mech = WWW::Mechanize->new( cookie_jar => HTTP::Cookies::Netscape->new( file => $cookies) );
$mech->agent_alias('Windows Mozilla'); #this is right user agent
$mech->get("https://www.facebook.com/login.php");
$mech->submit_form(
fields => {
    email =>'your username',
    pass => 'your password',
   }
);

open(my $out, ">",  "output_page.html") or die "Can't open output_page.html: $!"; #make lexical variables using my
print $out $mech->content;

我建议您阅读 WWW ::机械化文档

许多其他用户建议这种类型的登录使用工具是对他们的ToS.So请检查 Facebook API

Note: As many other users suggested this type of login using tools are against their ToS.So please check Facebook API.

这篇关于Perl Facebook登录与Mechanize失败的cookie错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆