我正在尝试登录此网站:https : //www.blackrock.com/userplatform/signOn
我正在使用以下脚本来执行此操作:
import requests
from bs4 import BeautifulSoup
headers = {
'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.12; rv:55.0) Gecko/20100101 Firefox/55.0'
}
resp = requests.get('https://www.ishares.com/us/sign-on.saml', headers=headers)
soup_object = BeautifulSoup(resp.text, 'html.parser')
csrf = soup_object.select_one('meta[name="_csrf"]').get('content')
login_data = dict(userName='USERNAME', password='PASSWORD', csrfmiddlewaretoken=csrf)
r = requests.post('https://www.blackrock.com/userplatform/signOn', data=login_data, headers={"Referer": "https://www.blackrock.com"})
但是,当我在邮递员中运行脚本时,它给了我禁止的 403 错误消息。有人可以建议我做错了什么吗?
该站点甚至共享了一个脚本,用于登录其门户并下载一些文件。但是它是用perl写的。共享该脚本以供参考。但我想用python来做。
use strict;
use File::Basename;
use Getopt::Long;
use WWW::Mechanize;
use URI qw( );
my $thisScript = basename($0);
print "==START $thisScript==\n";
my ($help, $proxy, $username, $password);
my $urlsToBeDownloaded = "file-url-list.txt";
my $url = "https://www.ishares.com/us/sign-on.saml";
usage() if (@ARGV < 2 or ! GetOptions('proxy:s' => \$proxy,
'username=s' => \$username,
'password=s' => \$password)
or defined $help);
if ($username eq "" || $password eq "") {
usage();
}
my $mech = WWW::Mechanize->new();
if($proxy ne ""){
$mech->proxy(['http', 'https'], $proxy);
}
$mech->get($url);
$mech->submit();
my $ctoken = $mech->field('ctoken');
$mech->get($mech->uri());
$mech->submit_form(
form_number => 1,
fields => {
userName => $username,
password => $password,
ctoken => $ctoken
}
);
吃鸡游戏
明月笑刀无情
相关分类