【问题标题】:How to bypass web site redirect screen?如何绕过网站重定向屏幕?
【发布时间】:2019-12-09 11:01:17
【问题描述】:

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

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

我下载了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();
});

【问题讨论】:

  • 你想用 PHP 废弃 javascript 网站吗? 叹息 ...或者我不明白你的问题?
  • 你的爬虫也需要维护cookie登录。
  • 所以您尝试废弃example2.com,但为了做到这一点,您还需要从example1.com 进行有效登录?
  • @Flash 迅雷 |是的,我试图抓取网页,但我不确定网站是否使用 JavaScript 进行重定向,因为当我禁用 JavaScript 时,页面再次重定向
  • @Ahmed Saleh | example2.com 是一个类似 egghead.io 的网站,用于销售课程。我需要提交表单才能登录,然后下载课程。问题是登录页面受waite screen保护

标签: php goutte


【解决方案1】:

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

  • 设置为 true 以启用最大数量为 5 的正常重定向 重定向。这是默认设置。
  • 设置为 false 以禁用重定向。
  • 传递一个包含“max”键的关联数组来指定 最大重定向数,并可选择提供“严格”键 指定是否使用严格的符合 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";
});

【讨论】:

  • 感谢您的回复,但您的回答无效
猜你喜欢
  • 2013-08-17
  • 2014-03-02
  • 1970-01-01
  • 2019-03-14
  • 1970-01-01
  • 2015-05-07
  • 2023-03-22
  • 1970-01-01
  • 2014-07-31
相关资源
最近更新 更多