Goutte 爬虫获取样式
Goutte crawler get style
我正在使用 Goutte 爬虫。
因此,在几个小时内,我试图在具有特定查询的搜索页面中获取 div 的样式属性,并且此样式具有 Background-img。
所以首先我通过
向 url 发出了 GET 请求
$crawler = $client->request('GET',"https://www.esheeq.net/search/مسلسل+علي+رضا");
然后被
抓取
$crawler->filter(".imgBg")->attr("style")
并打印出来,它起作用了,但问题是当我更改搜索查询时,例如 (https://www.esheeq.net/search/مسلسل+الغرفة+الحمراء),它会抛出错误
Fatal error: Uncaught InvalidArgumentException: The current node list is empty. in C:\xampp\htdocs\esheeqAPI\vendor\symfony\dom-crawler\Crawler.php:550 Stack trace: #0 C:\xampp\htdocs\esheeqAPI\api\functions.php(8): Symfony\Component\DomCrawler\Crawler->attr('style') #1 C:\xampp\htdocs\esheeqAPI\api\tests.php(4): InsertMultipleSeries() #2 {main} thrown in C:\xampp\htdocs\esheeqAPI\vendor\symfony\dom-crawler\Crawler.php on line 550
但是当我打开 url 时,我要求它显示 div of class imgBg 具有样式属性。那为什么会报错,我该如何解决。
也许可以尝试这样做:
use Symfony\Component\DomCrawler\Crawler;
// you need to urlencode arabic characters, because php doesn't do that automatically
$url = "https://www.esheeq.net/search/" . urlencode( "مسلسل+الغرفة+الحمراء" );
$html_content = file_get_contents($url);
// and then;
$crawler = new Crawler( $html_content );
$crawler->filter(".imgBg")->attr("style");
如果它不起作用请告诉我
我正在使用 Goutte 爬虫。 因此,在几个小时内,我试图在具有特定查询的搜索页面中获取 div 的样式属性,并且此样式具有 Background-img。 所以首先我通过
向 url 发出了 GET 请求 $crawler = $client->request('GET',"https://www.esheeq.net/search/مسلسل+علي+رضا");
然后被
抓取$crawler->filter(".imgBg")->attr("style")
并打印出来,它起作用了,但问题是当我更改搜索查询时,例如 (https://www.esheeq.net/search/مسلسل+الغرفة+الحمراء),它会抛出错误
Fatal error: Uncaught InvalidArgumentException: The current node list is empty. in C:\xampp\htdocs\esheeqAPI\vendor\symfony\dom-crawler\Crawler.php:550 Stack trace: #0 C:\xampp\htdocs\esheeqAPI\api\functions.php(8): Symfony\Component\DomCrawler\Crawler->attr('style') #1 C:\xampp\htdocs\esheeqAPI\api\tests.php(4): InsertMultipleSeries() #2 {main} thrown in C:\xampp\htdocs\esheeqAPI\vendor\symfony\dom-crawler\Crawler.php on line 550
但是当我打开 url 时,我要求它显示 div of class imgBg 具有样式属性。那为什么会报错,我该如何解决。
也许可以尝试这样做:
use Symfony\Component\DomCrawler\Crawler;
// you need to urlencode arabic characters, because php doesn't do that automatically
$url = "https://www.esheeq.net/search/" . urlencode( "مسلسل+الغرفة+الحمراء" );
$html_content = file_get_contents($url);
// and then;
$crawler = new Crawler( $html_content );
$crawler->filter(".imgBg")->attr("style");
如果它不起作用请告诉我