我需要从一个网站抓取一些数据。一些原因目标服务器,一些爬行能不能成功,需要retry.The代码如下:PHP GOUTTE尝试和重试
private function fetchArchive($id) {
$url = 'xxxx/' . $id;
$attempt = 0;
$base = null;
if (Goutte::request('GET', $url)->filter('#table')->count() < 1) {
do {
try {
$base = Goutte::request('GET', $url)->filter('#table')->text();
} catch (InvalidArgumentException $e) {
$attempt++;
sleep(2);
break;
}
} while ($attempt <= 5);
}
其实try($base = Goutte::request('GET', $url)->filter('#table')->text())
不工作,我收到
"production.ERROR: InvalidArgumentException: The current node list is empty."
怎么办我解决了这个问题?