0

I am using CURL to generate data. Though the site is not providing any other format for extraction So what I have did simply paas the url and retrieving data in HTML this is my script is retrievning. Can I convert that html data to any other format like JSON or XML so it would easy for me to parse HTML in PHP. If I can't get data in JSON/XL how would I extract data that is parse it according to my relevance. I got some code to get it in json.

function get_json_content($json_url = '') {
    $ch = curl_init($json_url);
    $options = array(
        CURLOPT_RETURNTRANSFER => true,
        CURLOPT_HTTPHEADER => array('Content-type: application/json'),
        CURLOPT_TIMEOUT => 160,
        CURLOPT_FOLLOWLOCATION => 1
    );

    curl_setopt_array($ch, $options);               // Setting curl options
    $result = curl_exec($ch);                       // Getting jSON result string
    return $result;
}

$json_url = 'http://www.evertek.com/viewpart.asp?auto=78053&cat=45#.UKZWHme5JI4';
$get_result = get_json_content($json_url);
die($get_result);

This $get_result is receving in html. Please help me my motto is to extract or parse data in proper format no matter wheresoever format it is in. I just want to easily parse data so I can use it with PHP.

Nikos Tsirakis
  • 709
  • 4
  • 8
Sankalp
  • 1,300
  • 5
  • 28
  • 52

2 Answers2

0

You can only use what CURL is giving you back, and CURL can only get what it's given - in this case, HTML.

HTML isn't difficult to work with, take a look at the answers here: How do you parse and process HTML/XML in PHP?

Community
  • 1
  • 1
BenOfTheNorth
  • 2,904
  • 1
  • 20
  • 46
0

Trying to retrieve data from a full website is not an easy thing. You would want to use an api that a website supports to provide you data in a meaningful manner that is easy for you to manipulate.

You need to review some tutorials pertaining to website scraping otherwise you're going to have to parse html and strip out useless information.

James McDonnell
  • 3,600
  • 1
  • 20
  • 26