Question

The site is http://www.nokia.com/in-en/support/warranty-check I am posting data to a textbox and Submit button which are like this

<input maxlength="15" id="imei_code" type="text"></input>
<input class="button submit" value="Submit" type="submit"></input>

and when the submit button is pressed it shows the processed data on the page and the Url is changed to http://www.nokia.com/in-en/support/warranty-check#main

When I run the code below then it returns blank page.

<?php
function post_to_url($url, $data) {
$fields = '';
foreach($data as $key => $value) { 
  $fields .= $key . '=' . $value . '&'; 
}
rtrim($fields, '&');

$post = curl_init();

curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_POST, count($data));
curl_setopt($post, CURLOPT_POSTFIELDS, $fields);
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);

$result = curl_exec($post);

curl_close($post);
return $result;
}

$data = array(
"pin_code" => "359746040018553",
"button submit" => "Submit"
);


$scraped_page = post_to_url("http://www.nokia.com/in-en/support/warranty-check", $data);


$scraped_data = scrape_between($scraped_page, "<p>", "</p>"); 

echo $scraped_data; 

?>

I cannot get it working I want all the data inside the

element i.e

Serial number (IMEI): 359746040018553 Warranty: Out of warranty

Était-ce utile?

La solution

Try this one:

$number = 'some-number';
$url = 'http://www.nokia.com/wal/care/warranty/?r=true&locale=en_IN&productId=&inst=&deviceId='.$number;
$post = curl_init();
curl_setopt($post, CURLOPT_URL, $url);
curl_setopt($post, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($post);
curl_close($post);
print_r(json_decode($result));

It will output a json like below:

stdClass Object
(
    [warrantyStatus] => N    <-- this checks whether it has warranty or not!
    [errorMessage] => 
    [token] => 4551c7686...
    [productCode] => xxxxx
    [pp1] => N
    [pp2] => N
    [pp3] => Y
    [pp4] => Y
    [typeDesignator] => RM-xxx
    [isValidIMEI] => Y
    [imei] => 
)

Autres conseils

first of all fix the double quote:

$scraped_data = scrape_between($scraped_page, "<span class=\"pin_placeholder\">", "</span>");
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top