public function process()
{
$crawler = $this->client->request($this->plan['method'], $this->plan['uri']);
if (isset($this->plan['selector'])) {
$selection = $crawler->filter($this->plan['selector']);
} elseif (isset($this->plan['xpath'])) {
$selection = $crawler->filterXPath($this->plan['path']);
}
if ($this->plan['images']) {
$images = $selection->filterXPath('//img');
if (iterator_count($images) > 1) {
foreach ($images as $image) {
$crawler = new Crawler($image);
$info = parse_url($this->plan['uri']);
$url = $info['scheme'] . '://' . $info['host'] . '/' . $crawler->attr('src');
if (strpos($crawler->attr('src'), 'http') === 0) {
$url = $info['scheme'] . '://' . $info['host'] . '/' . $this->plan['path'] . $crawler->attr('src');
}
copy($url, SCRYPHP_STORAGE_PATH_IMG . DIRECTORY_SEPARATOR . substr(strrchr($url, "/"), 1));
}
}
}
file_put_contents(SCRYPHP_STORAGE_PATH_TXT . DIRECTORY_SEPARATOR . time() . uniqid(time(), true) . '.txt', $selection->text());
return $selection->text();
}