使用panther库从bing抓取的PHP图像显示chrome端口9515已经在使用

使用panther库从bing抓取的PHP图像显示chrome端口9515已经在使用,php,web-scraping,symfony-panther,Php,Web Scraping,Symfony Panther,我试图从rss提要中抓取图像,方法是传递我在bing上搜索图像的前3个单词,并尝试抓取图像。我的代码正在工作,但我总是得到端口9515已在使用的错误。我已经添加了杀死端口的代码,但它不工作,请帮助我。我从这个url获取引用来构建我的代码https://www.thoughtfulcode.com/php-web-scraping//请帮帮我 代码 include ('vendor/autoload.php'); error_reporting(E_ERROR | E_PARSE);

我试图从rss提要中抓取图像,方法是传递我在bing上搜索图像的前3个单词,并尝试抓取图像。我的代码正在工作,但我总是得到端口9515已在使用的错误。我已经添加了杀死端口的代码,但它不工作,请帮助我。我从这个url获取引用来构建我的代码
https://www.thoughtfulcode.com/php-web-scraping/
/请帮帮我

代码

 include ('vendor/autoload.php');
    
 error_reporting(E_ERROR | E_PARSE);

 $url="https://timesofindia.indiatimes.com/rssfeedstopstories.cms";
 $xml = simplexml_load_file($url);
 $array = json_decode(json_encode($xml), true);
 $description=array();
 $i_size=sizeof($array['channel']['item'])-1;
 for($i=0;$i<sizeof($array['channel']['item']);$i++){
      $title=$array['channel']['item'][$i]['title'];
      $keyword_array=explode(" ",$title);
      $keyword=$keyword_array[0].' '.$keyword_array[1].' '.$keyword_array[2];
      download_feed_image($keyword);
      if($i_size==$i){
       echo "done";
    }
 }


    function download_feed_image($keyword){
       try {
          $client = \Symfony\Component\Panther\Client::createChromeClient();
          $crawler = $client->request('GET', 'https://www.bing.com/images/search?q='.$keyword.'&form=HDRSC2&first=1&cw=1349&ch=657');
          $fullPageHtml = $crawler->html();
          $pageH1 = $crawler->filter('.iusc')->attr('href');
          $img_tag=null;
          parse_str($pageH1,$img_tag);
          $file_name = basename($img_tag['mediaurl']);
          file_put_contents( $file_name,file_get_contents($img_tag['mediaurl']));
        } catch (Exception $e) {
            echo $e->getMessage();
        } finally {
            $client->quit();
        }
        exec("kill -9 $(lsof -t -i:9515)");
 }
include('vendor/autoload.php');
错误报告(E|u错误| E|u解析);
$url=”https://timesofindia.indiatimes.com/rssfeedstopstories.cms";
$xml=simplexml\u加载文件($url);
$array=json_decode(json_encode($xml),true);
$description=array();
$i_size=sizeof($array['channel']['item'])-1;
对于($i=0;$irequest('GET','https://www.bing.com/images/search?q=“.$keyword.&form=HDRSC2&first=1&cw=1349&ch=657”);
$fullPageHtml=$crawler->html();
$pageH1=$crawler->filter('.iusc')->attr('href');
$img_tag=null;
parse_str($pageH1,$img_标记);
$file_name=basename($img_标记['mediaurl']);
文件内容($file\u name,file\u get\u contents($img\u tag['mediaurl'));
}捕获(例外$e){
echo$e->getMessage();
}最后{
$client->quit();
}
行政长官(kill-9$(lsof-t-i:9515));;
}

只需重新启动计算机帮助即可杀死Chrome浏览器实例或 如果您在terminal
pkill chrome中使用Ubuntu类型

$client->quit();
浏览器忙且未应答时不工作:( 在退出Chrome浏览器之前,您需要删除临时数据

$client->close();
$client->quit();
另外,你可以在这里看到Chrome浏览器的状态