Jump to content

cURL to get body of webpage


Vivid Lust

Recommended Posts

Hey guys

 

I have the following code and am trying to get the body of the webpage, however it is not currently working  and the array at the end is empty. Any help appreciated!!!!!

 

Code:

<?php

$word = $_GET['word'];

function get_web_page( $url,$curl_data )
{
    $options = array(
        CURLOPT_RETURNTRANSFER => true,         // return web page
        CURLOPT_HEADER         => false,        // don't return headers
               CURLOPT_ENCODING       => "",           // handle all encodings
        CURLOPT_USERAGENT      => "spider",     // who am i
        CURLOPT_AUTOREFERER    => true,         // set referer on redirect
        CURLOPT_CONNECTTIMEOUT => 120,          // timeout on connect
        CURLOPT_TIMEOUT        => 120,          // timeout on response
        CURLOPT_MAXREDIRS      => 10,           // stop after 10 redirects
        CURLOPT_POST            => 1,            // i am sending post data
        CURLOPT_POSTFIELDS     => $curl_data,    // this are my post vars
        CURLOPT_SSL_VERIFYHOST => 0,            // don't verify ssl
        CURLOPT_SSL_VERIFYPEER => false,        //
        CURLOPT_VERBOSE        => 1                //
    );

    $ch      = curl_init($url);
    curl_setopt_array($ch,$options);
    $content = curl_exec($ch);
    $err     = curl_errno($ch);
    $errmsg  = curl_error($ch) ;
    $header  = curl_getinfo($ch);
    curl_close($ch);

  //  $header['errno']   = $err;
  //  $header['errmsg']  = $errmsg;
   //$header['content'] = $content;
    return $content;
}

$curl_data = "?tranword=".$word;
$url = "http://www.wordreference.com/es/translation.asp?tranword=".$word;
$response = get_web_page($url,$curl_data);
preg_match('~<body>(.*)</body>~', $response, $output);
print_r($output); 


?>

 

Thanks lots,

 

Jake

Link to comment
https://forums.phpfreaks.com/topic/214807-curl-to-get-body-of-webpage/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.