I'm trying to scrape some content from a site. I eventually discovered that it requires cookies, so I solved that with the guzzle cookie plugin. It's strange because I cannot get the content from doing a var_dump, but it will show the page if I do 'echo' which makes me think there is some dynamic data call, which gets the data. I'm quite used to api with guzzle but not sure I should treat this?, thanks
If I use domcrawler I get an error.
Code -
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\DomCrawler\Crawler;
use Guzzle\Http\Client;
use Guzzle\Plugin\Cookie\CookiePlugin;
use Guzzle\Plugin\Cookie\CookieJar\ArrayCookieJar;
$cookiePlugin = new CookiePlugin(new ArrayCookieJar());
$url = 'http://www.myurl.com';
// Add the cookie plugin to a client
$client = new Client();
$client->get();
$client->addSubscriber($cookiePlugin);
// Send the request with no cookies and parse the returned cookies
$client->get($url)->send();
// Send the request again, noticing that cookies are being sent
$request = $client->get($url);
$response = $request->send();
var_dump($response);
$crawler = new Crawler($response);
foreach ($crawler as $domElement) {
print $domElement->filter('a')->links();
}
error
Expecting a DOMNodeList or DOMNode instance, an array, a
string, or null, but got "Guzzle\Http\Message\Response