Answer the question
In order to leave comments, you need to log in
Why doesn't the Guzzle POST request to fill out a third party form work?
The library has a book search form . But initially there is no tag and inputs with the necessary name on the page.
The user writes the title of the book and presses the button. As I understand it, after that, a script is triggered that reads the filled data, forms a real form with them and sends it using the POST method.
Without reloading the page, the user gets the search result:
I need to programmatically fill in this form and display the result page. I analyze using the Network panel what data is being transmitted, I repeat the request with these parameters, but it does not work .<form>
require 'vendor/autoload.php';
// Подключаем класс Client
use GuzzleHttp\Client;
// Инициализируем класс для работы с удаленными веб-ресурсами
$client = new Client();
// Делаем запрос, получаем ответ
$response = $client->request("POST", "http://opac.rgub.ru/cgiopac/opacg/opac.exe", [
"form_params" => [
"arg0" => "GUEST",
"arg1" => "GUESTE",
"TypeAccess" => "FreeAccess",
"_errorXsl" => "/opacg/html/common/xsl/error.xsl",
"_wait" => "6M",
"_xsl" => "/opacg/html/search/xsl/search_results.xsl",
"_version" => "2.0.0",
"_service" => "STORAGE:opacfindd:FindView",
"outform" => "SHOTFORM",
"length" => "15",
"query/body" => "%28TI+%CE%E1%EB%EE%EC%EE%E2%29",
"query/open" => "{NC:<span class='red_text'>}",
"query/close" => "{NC:</span>}",
"userId" => "GUEST",
"session" => "495180",
"iddb" => "5",
"level[0]" => "Full",
"level[1]" => "Retro"
]
]);
// Выводим ответ
echo $response->getBody();
"arg0" => "GUEST",
"arg1" => "GUESTE",
"TypeAccess" => "FreeAccess"
// Находим нужное из хтмла выдачи
$htmlRGBM = $response->getBody();
$docRGBM = new DOMDocument();
@$docRGBM->loadHTML($htmlRGBM);
$xpathRGBM = new DOMXpath($docRGBM);
echo $xpathRGBM->query('//entry[1]/text()')[0]->nodeValue;
Answer the question
In order to leave comments, you need to log in
Look in development tools what request flies to the server.
The first thing I noticed was the encoding of the query/body parameter through urlencode.
Next, try throwing headers: referer and user-agent at least.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question