public function afterRequest(Request $request) { //The HTMLParser sets up the XPath document that we are going to use to extract the result $parser = new HTMLParser($request->getResponse()->getBody()); $result = $parser->query("//*[@class='ent-name']"); //Add each product to the result set foreach ($result as $pokemon) { $this->result[] = $pokemon->nodeValue; } }
public function afterRequest(Request $request) { //The HTMLParser sets up the XPath document that we are going to use to extract the result $parser = new HTMLParser($request->getResponse()->getBody()); $result = $parser->query("//a[@class='productTitle']"); //Add each product to the result set foreach ($result as $product) { $this->result[] = trim($product->nodeValue); } //Increment the page counter in order to construct the correct URL for the next round-trip $this->page++; }
/** * The function in which the actual remote cal is made * * @param Request $request * @throws InvalidRequestUrl */ public function doRequest(Request $request) { if (is_null($request->getUrl()) || $request->getUrl() == '') { throw new InvalidRequestUrl(); } //Using Guzzle instead of the old curl //We also use the cacert.pem to verify all SSL connections $client = new Client(); $result = $client->request($request->getMethod(), $request->getUrl(), ['headers' => $request->getHeaders(), 'verify' => __DIR__ . '/cacert.pem', 'proxy' => $request->getProxies()]); //Generate the request object and inject it into the request $response = new Response(); $response->setStatus($result->getStatusCode()); $response->setBody($result->getBody()); $response->setHeaders($result->getHeaders()); $request->setResponse($response); }