[英]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请求选项来自定义重定向行为。
参考: 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.