FriendsOfPHP / Goutte

Goutte, a simple PHP Web Scraper
MIT License
9.26k stars 1.01k forks source link

Setting user-agent not working #449

Open jonyking opened 2 years ago

jonyking commented 2 years ago

Hello,

we've got the problem that setting the user-agent will end up in "You use an unknown device or you are in privacy mode", so we can not access some websites. Do you have a solution for this?

require('vendor/autoload.php');
set_time_limit('0');

error_reporting(E_ALL);

/*
$client = new \Goutte\Client([
]);*/
$driver = new \Behat\Mink\Driver\GoutteDriver();

$session = new \Behat\Mink\Session($driver);

// start the session
$session->start();
$session->visit('URL');

$page = $session->getPage();

$loginForm = $page->findById('loginForm');
$loginFormUsername = $loginForm->findField('userName');
if (null === $loginFormUsername) {
throw new \Exception('The element is not found');
} else {
$loginFormUsername->setValue('USERNAME');
}
$loginFormPassword = $loginForm->findField('password');
if (null === $loginFormPassword) {
throw new \Exception('The element is not found');
} else {
$loginFormPassword->setValue('PASSWD');
}

$loginForm->submit();
print_r($loginForm);
jonyking commented 2 years ago

Some suggestions?

georaldc commented 2 years ago

Have you tried using a your own guzzle instance that has a custom user agent defined?