How do I store rank for each website in MySQL using this API
开发者_JAVA百科This is an api which gives you rank of any website..
http://apps.compete.com/sites/google.com/trended/rank/?apikey=ee39792b8044f3d3b8bf38f6e1ec91fd&latest=1
I do have more than 1000 website list in note pad. what I want is I need to store rank for each website using this API to MySQL database. I want to do this from my local machine..I have configured webserver and PHP MySQL on it. How do I do this??
Can anyone give me a PHP code for this??
sorry the key was wrong I updated it
This should give you some idea:
<?php
//connect to your database
mysql_connect("localhost", "username", "password");
mysql_select_db("somedb");
//read your text file into an array, one entry per line
$lines = file('filename.txt');
//loop through each website URL you read from the file
foreach ($lines as $website_url) {
//make the request to the compete API
$response = file_get_contents("http://apps.compete.com/sites/" . $website_url . "/trended/rank/?apikey=0sdf456sdf12sdf1");
//the error I saw was in JSON, so decode the request
$response = json_decode($request);
//get the rank from the response, I don't know what a real response looks like
$rank = $response['something'];
//insert the website URL and its rank into your table
mysql_query("INSERT INTO website_ranks (website_url, rank) VALUES ('" . mysql_real_escape_string($website_Url) . "', " . $rank . ")");
}
?>
I don't have enough details from you to write working code, though.
精彩评论