问题描述
我在 symfony 中使用 panther 从网站抓取数据。检测到我的 chromedriver。但我收到此错误消息“30 秒后无法连接到 chrome(“http://127.0.0.1:9515/status”已超时。)。我尝试更改端口,但什么也没有。
在 CLI 中:“警告:fsockopen():无法连接到 127.0.0.1:9515”
如果有人有想法,我很感兴趣!提前致谢!
我的代码:
<?PHP
namespace App\Service;
use invalidargumentexception;
use \Symfony\Component\Panther\Client;
use Symfony\Component\HttpKernel\KernelInterface;
class ScraperService {
private $appKernel;
public function __construct(KernelInterface $appKernel)
{
$this->appKernel = $appKernel;
}
public function getDataFromCarrefour(){
$path = $this->appKernel->getProjectDir().'/drivers\chromedriver.exe';
$results = array();
$client = Client::createChromeClient($path,[
'--user-agent="Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/65.0.3312.0 Safari/537.36"','--headless',]);
$crawler = $client->request('GET','https://www.carrefour.fr/p/*-3600900006972');
try{
$results['ingredients'] = $crawler->filter('#product-detail-page > div.pdp__secondary > div > div > div.secondary-details__left > div.secondary-details-blocks > div:nth-child(4) > div > p')->text();
$results['images'] = $crawler->filter('#data-produit-image > div > div.carousel__wrapper > div.carousel__siema > div > div:nth-child(1) > div > div > img')->attr('src');
$results['title'] = $crawler->filter('#data-produit-card > div.main-details__pricing > div > div > div > div.pdp-pricing__block-left > div.product-card-price > div > span')->text();
$results['score'] = $crawler->filter('#data-produit-card > div.main-details__scores > a.product-badge__link.product-badge--flag-nutriscore > picture > img')->attr('src');
}catch (invalidargumentexception $e){
dd($e);
$results['error'] = 'EAN unreconized !';
}
$client->close();
return $results;
}
}
?>
“C:\Users\gelinn\Desktop\base-veille\vendor\symfony\panther\src\ProcessManager\WebServerReadinessProbeTrait.PHP”中的 RuntimeExeption(第 82 行):
if ($e) {
$message = $e->getMessage();
} else {
$message = "Status code: $statusCode";
}
throw new \RuntimeException("Could not connect to $service after $timeout seconds ($message).");
}
usleep(1000);
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)