0

I am trying to get the price of a product via cURL and DOM (at first simple html dom). But it seems like that cURL is returning an empty string. Does somebody know how I should fix this?

This is from the wordpress debug log: [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 didn't return an error when I used: 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
Craig van Tonder
  • 7,497
  • 18
  • 64
  • 109
Martijn
  • 105
  • 1
  • 1
  • 5

1 Answers1

0

Have you displayed curl_error($ch)? Because it tells me "SSL certificate problem: unable to get local issuer certificate". You might want to look into curl: (60) SSL certificate : unable to get local issuer certificate

kmoser
  • 8,780
  • 3
  • 24
  • 40
  • Tried it but it doesn't work and no error's. I know that errors will be printed to the screen when there are any because when I deliberately mess up the code, like deleting `curl_setopt($ch, CURLOPT_URL, $Url);`, then it does print an error. – Martijn Nov 18 '18 at 14:58
  • cURL errors don't get printed to the screen automatically. You're thinking of syntax errors in your code. – kmoser Nov 19 '18 at 21:19