繁体   English   中英

如何绕过网站重定向屏幕?

[英]How to bypass web site redirect screen?

我尝试通过抓取方式下载网页的内容,但是主要的问题是我无法绕过网站的重定向。 例如,当我尝试登录网站并提交登录表单时。 我看到等待页面,而只是等待页面。

但是在等待页面后在浏览器中我重定向到个人资料页面

我下载了goutte并创建了脚本,但是以提交形式存在问题,因为当我提交错误的密码或用户名时,我会看到错误的密码,但是当我输入正确的用户名和密码时,我会看到等待图像重定向

第一次编辑

根据更新响应我的代码是

<?php

require_once  'vendor/autoload.php';


use Goutte\Client;

$client = new Client();

$url = 'https://egghead.io/users/sign_in';
$username = 'xxxx';
$password = 'xxxx';

$crawler = $client->request('GET', $url, [
    'allow_redirects' => true
]);

$form = $crawler->selectButton('Sign In')->form();

$crawler = $client->submit($form, array('user[email]' => $username, 'user[password]' => $password));

$crawler->filter('body')->each(function ($node){
    print $node->html();
});

Goutte会自动跟随重定向,除非您告知您不这样做。 您可以使用allow_redirects请求选项来自定义重定向行为。

  • 设置为true以启用最多5个重定向的常规重定向。 这是默认设置。
  • 设置为false可禁用重定向。
  • 传递一个包含'max'键的关联数组,以指定最大重定向数,并可选地提供一个'strict'键值,以指定是否使用严格的RFC兼容重定向(这意味着将POST请求与POST请求进行重定向,而不是执行大多数操作浏览器会通过GET请求重定向POST请求)。

参考: http : //docs.guzzlephp.org/en/latest/quickstart.html#redirects

更新:

$crawler = $client->request('GET', 'http://egghead.io', [
    'allow_redirects' => true
]);
$crawler = $client->click($crawler->selectLink('Sign in')->link());
$form = $crawler->selectButton('Sign in')->form();
$crawler = $client->submit($form, array('login' => 'fabpot', 'password' => 'xxxxxx'));
$crawler->filter('.flash-error')->each(function ($node) {
    print $node->text()."\n";
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM