[英]How to get the fastest response from Guzzle async http client in PHP
[英]Guzzle Http Client ambiguous response
這是我在其他文件中的代碼
use Symfony\Component\DomCrawler\Crawler;
$guzzle = new GuzzleHttp\Client(['base_url' => 'http://pricematch.pk/mobile/samsung-galaxy-s6-80514-price-in-Pakistan']);
$response = $guzzle->get();
$crawler = new Crawler((string)$response->getBody());
echo $crawler->filter('.product-shop-wrapper .price')->text()."\r\n";
此URL中的URL是硬編碼的,並且此URL成功回顯了過濾的文本。 當以下代碼中每個循環中的相同url /任意url來自變量時
$guzzle = new GuzzleHttp\Client(['base_url' => 'pricematch.pk/mobile-phone-prices-in-pakistan']);
$response = $guzzle->get();
$crawler = new Crawler((string)$response->getBody());
$crawler->filter('.product-name')->each(function ($node,$counter) {
echo $counter." ".$node->text()."\r\n";
$url=$node->filter('a')->extract(array('href'))[0]."\r\n";
echo $url."\r\n";
$url='http://pricematch.pk'.$url;
echo $url;
$guzzle = new GuzzleHttp\Client(['base_url' => $url]);
$response = $guzzle->get();
$crawler = new Crawler((string)$response->getBody());
搜尋器會引發異常,指出當前節點列表為空。 href返回一個相對URL,我在上面的代碼中附加了根URL。 我已經多次打印了結果網址。 即使URL與代碼#1中的相同,過濾器也會引發異常。 我究竟做錯了什么?
更新2 :我剛剛發現code2搜尋器中的數據來自
pricematch.pk/mobile-phone-prices-in-pakistan
它應該從哪里來
$ url
這是怎么回事?
愚蠢的我。 在上述代碼中提取URL時,我連接了換行符,該換行符可能將URL編碼為__,出現在URL的末尾,這基本上改變了URL,從而改變了響應。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.