/**
  * @param $item_url
  * @param $i
  * @return mixed
  */
 public function getItem($itemUrl, $i)
 {
     $client = new Client();
     //Go to the Sainsburys item page
     $crawler = $client->request('GET', $itemUrl);
     // Title
     $title = $crawler->filter('#content > div.section.productContent > div.pdp > div > div.productTitleDescriptionContainer > h1')->text();
     // Unit price
     $price = $crawler->filter('div.priceTab > div.pricing > p.pricePerUnit')->text();
     $priceFormatted = preg_replace("/([^0-9\\.])/i", "", $price);
     // Size
     $response = $client->getInternalResponse();
     $size = $response->getHeader('Content-Length');
     $sizeFormatted = $this->getFormattedSizeKB($size);
     //convert from bytes to kilobytes
     // Description
     $description = $crawler->filter('#information > productcontent > htmlcontent > div.productText')->text();
     // Results
     $this->items['results'][] = ['title' => trim($title), 'size' => $sizeFormatted, 'unit_price' => $priceFormatted, 'description' => trim($description)];
     return $this->items['results'][$i];
 }
Example #2
0
 /**
  * Get's the content length of the latest request.
  *
  * @return string
  */
 public function getResponseSize()
 {
     $response = $this->client->getInternalResponse();
     return $response->getHeader('Content-Length');
 }