重定向后如何检查站点?域名爬虫。功能测试
How to check a site after redirection? DomCrawler. Functional Testing
重定向后如何正确断言?
$crawler = $client->submit($form);
$client->followRedirect();
//$response = $client->getResponse()->getContent();
$this->assertTrue($crawler->filter('html:contains("foo")')->count() > 0);
调试器显示 $response
具有我期望的内容,带有 foo
字,但断言失败。
将重定向分配给抓取工具。
试试这个代码:
$crawler = $client->submit($form);
$this->assertTrue($client->getResponse()->isRedirect(),'Submit ok');
// Assign the redirect to the crawler
$crawler = $client->followRedirect();
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Correct redirect to page ok");
$this->assertTrue($crawler->filter('html:contains("foo")')->count() > 0);
希望对您有所帮助
重定向后如何正确断言?
$crawler = $client->submit($form);
$client->followRedirect();
//$response = $client->getResponse()->getContent();
$this->assertTrue($crawler->filter('html:contains("foo")')->count() > 0);
调试器显示 $response
具有我期望的内容,带有 foo
字,但断言失败。
将重定向分配给抓取工具。 试试这个代码:
$crawler = $client->submit($form);
$this->assertTrue($client->getResponse()->isRedirect(),'Submit ok');
// Assign the redirect to the crawler
$crawler = $client->followRedirect();
$this->assertEquals(200, $client->getResponse()->getStatusCode(), "Correct redirect to page ok");
$this->assertTrue($crawler->filter('html:contains("foo")')->count() > 0);
希望对您有所帮助