使用Guzzle / Goutte(PHP,调试)从网站导航表单并获取DOM元素

问题描述 投票:0回答:1

我对PHP还是相当陌生,他在填写一些表格后与Goutte / Guzzle一起从网站上获取一些基本信息。

但是我找不到问题(可能有很多问题),因为我找不到一种方法来显示或控制台记录任何结果或问题。该脚本以代码0结尾,但不返回任何内容。关于如何打印当前存储在$ client中的内容的技巧已经很长了。

这是我尝试运行的全部代码,其中包含一堆注释以进行澄清。很抱歉使用这么大的块,但是其中任何一个都可能有问题。

<?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并访问它时,会收到服务器超时响应。

php guzzle goutte
1个回答
0
投票

您应该使用调试。安装xDebug以在PHP中执行此操作。这也很容易集成到Phpstorm中。或者,使用var_dump()打印有关任何类型变量的调试信息到控制台。

© www.soinside.com 2019 - 2024. All rights reserved.