i want scrap data from other site to my create post blade, im use voku/simple_html_dom. when i try i get this error voku\helper\HtmlDomParser::loadHtml(): Argument #1 ($html) must be of type string, bool given
<?php
namespace App\Services;
use voku\helper\HtmlDomParser;
class Scrap
{
private $baseTarget = 'website';
private function init($path)
{
$curl = curl_init($this->baseTarget . $path);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13');
$html = curl_exec($curl);
curl_close($curl);
return HtmlDomParser::str_get_html($html);
}
public function getData()
{
$html = $this->init('/blog/howtoinstalllaravel');
// Wrapper
$wrapper = $html->findOne('#content');
// Get Title
$data['title'] = $wrapper->findOne('.lead')->innerText();
return $data;
}
}
Returns true on success or false on failure. However, if the CURLOPT_RETURNTRANSFER option is set, it will return the result on success, false on failure.
$html = curl_exec($curl);
if (! $html) { // failed
return 'Something went wrong';
}
return HtmlDomParser::str_get_html($html);