Я пытаюсь узнать цену продукта через cURL и DOM (сначала простой html dom). Но похоже, что cURL возвращает пустую строку. Кто-нибудь знает, как мне это исправить?
Это из журнала отладки WordPress: [17-Nov-2018 22:45:04 UTC] PHP Warning: DOMDocument::loadHTML(): Empty string supplied as input in /home/u1771p590/domains/removed.domain/public_html/store/wp-content/plugins/ff-banggood-updater/ff-banggood-updater.php on line 111.
.
cURL не возвращал ошибку, когда я использовал: curl_error($ch);
.
//**START cURL Scraper function
function curl_download($Url){
if (!function_exists('curl_init')){
die('cURL is not installed. Install and try again.');
}
//initiating cURL and downloading the webpage
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $Url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_COOKIE, 'countryCookie=%7B%22code%22%3A%22EE%22%2C%22name%22%3A%22Estonia%22%2C%22currency%22%3A%22EUR%22%7D');
$output = curl_exec($ch);
curl_close($ch);
//Test what the output is of cURL
var_dump($output);
//Create DOM object and load the html string from cURL
/*** a new dom object ***/
$dom = new domDocument;
/*** load the html into the object ***/
$dom->loadHTML($output);
/*** discard white space ***/
$dom->preserveWhiteSpace = false;
//Get the product price
/* $product_price = $html->find('.item_now_price', 0);
//$product_price = $product_price->plaintext;
//$product_price = trim($product_price,'€');
//$product_price = str_replace(",",".",$product_price);
//update_post_meta( 2278, '_purchase_price', esc_attr( $product_price ) ); */
//Return values in an associative array
//return array('product_price' => $product_price);
}
curl_download('https://www.banggood.com/6Pcs-Waterproof-Cube-Travel-Storage-Bags-Clothes-Pouch-Nylon-Luggage-Organizer-Travel-p-1141008.html');
//**END cURL Scraper