首页 > 解决方案 > 如何发出登录请求以登录 https://analytics.oag.com/analyser-client/home(Javascript 网站)

问题描述

我尝试使用命令卷曲

curl 'https://analytics.oag.com/analyser-client/home' -H 'Accept-Language: 
en-US,en;q=0.9' -H 'Connection: keep-alive' -H 'Accept-Language: en- 
US,en;q=0.9' -H 'Host: analytics.oag.com' -H 'User-Agent: Mozilla/5.0 
(Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) 
Chrome/66.0.3359.181 Safari/537.36' -H 'Content-Type: text/html;charset=UTF- 
8' --data '{"username":"test","password":"test"}'

但它似乎不起作用......不知道我错过了哪些部分......关于如何登录这个网站的任何想法?

标签: javascriptpython-3.xreactjscurlweb-crawler

解决方案


Not sure what parts am I missing- 您缺少 cookie 会话 id、referer 标头和X-Requested-With: XMLHttpRequest标头,并且您的 Content-Type 标头是错误的(应该是Content-Type: application/json),如果您在没有 cookie 会话的情况下访问它,登录页面也会自动加载两次(首先它会获得一个 cookie 会话,然后它会自行刷新),您可能应该按照套件登录。您特别提到了 python,我不知道如何在 python 中执行此操作,但这是我在 PHP 中使用hhb_curl执行此操作的方式:

<?php
declare(strict_types = 1);
require_once ('hhb_.inc.php');
$hc = new hhb_curl ( '', true );
// getting cookie session and refresh (dunno why we need to refresh, but the login page javascript is doing it, so follow suite)
$hc->exec ( 'https://analytics.oag.com/analyser-client/home' )->exec ( 'https://analytics.oag.com/analyser-client/home' );
$response = $hc->setopt_array ( array (
        CURLOPT_POST => 1,
        CURLOPT_URL => 'https://analytics.oag.com/analyser-client/broker-services/login/validate',
        CURLOPT_HTTPHEADER => array (
                'Content-Type: application/json',
                'Origin: https://analytics.oag.com', // i don't think curl set this header this automatically
                'X-Requested-With: XMLHttpRequest' 
        ),
        CURLOPT_POSTFIELDS => json_encode ( array (
                'username' => 'username?',
                'password' => 'password?' 
        ) ) 
) )->exec ()->getResponseBody ();
var_dump ( $response );
$parsed = @json_decode ( $response, true );
if (empty ( $parsed ) || $parsed ['status'] === 'ERROR') {
    throw new \RuntimeException ( 'failed to login! ' . $response );
}

推荐阅读