【发布时间】:2020-02-04 01:43:46
【问题描述】:
我对 PHP 还很陌生,并且在填写一些表格后使用 Goutte/Guzzle 从网站上获取一些基本信息。
但是我在查找问题时遇到了问题(可能有很多问题),因为我找不到显示或控制台记录任何结果或问题的方法。该脚本以代码 0 结束,但不返回任何内容。关于如何打印出当前存储在 $client 中的内容的提示已经有很长的路要走。
这是我试图与一堆 cmets 一起运行以进行澄清的整个代码。很抱歉使用了这么大的块,但其中任何一个都可能有问题。
<?php
use Goutte\Client;
use GuzzleHttp\Client as GuzzleClient;
class grabPlate
{
// WKZ
public function checkPlate
{
$goutteClient = new Client();
$guzzleClient = new GuzzleClient(array(
'cookies' => true,
'timeout' => 60,
));
$goutteClient->setClient($guzzleClient);
$crawler = $goutteClient->request('GET', 'https://kfz-portal.berlin.de/kfzonline.public/start.html?oe=00.00.11.000000');
//Click the first "Start" in the top left
$link = $crawler
->filter('a:contains("Start")')
->eq(0)
->link()
;
$crawler = $client->click($link);
//Check checkbox, fill in name and press the button
$buttonCrawlerNode = $crawler->selectButton('Weiter');
$form = $buttonCrawlerNode->form();
$form['gwt-uid-1']->tick();
$form['select2-hidden-accessible']->select('Herr');
$form['gwt-uid-4'] = 'John';
$form['gwt-uid-5'] = 'Doe';
$client->submit($form);
//Fill some Data into the forms and search
$buttonCrawlerNode = $crawler->selectButton('Button-3616');
$form = $buttonCrawlerNode->form();
$form['.kfzonline-KennzeichenGrossEb'] = 'AB';
$form['.kfzonline-KennzeichenGrossEn'] = '123';
$client->submit($form);
//Extract collection
$info = $crawler->extract('.collection');
//return 1 if something is inside collection, 0 if it's empty
if($info == NULL) {
return 1;
} else {
return 0;
}
}
}
?>
正如我所说,只是在 PHPStorm 中运行脚本会返回状态 0。但是当将其插入 API 并访问它时,我会收到服务器超时响应。
【问题讨论】: