Created
July 29, 2012 17:14
-
-
Save tamalw/3200328 to your computer and use it in GitHub Desktop.
Faster cURL action!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$searchURL = "http://services.runescape.com/m=hiscore/overall.ws"; | |
$perPage = 22; | |
$namesToReturn = 1; | |
for ($index = 1; $index <= $namesToReturn; $index++) | |
{ | |
// $search = rand(1, 500000); | |
$search = 183696; | |
$searchWComma = number_format($search); | |
$searchString = "?table=0&category_type=0&rank=$search"; | |
$ch = curl_init(); | |
curl_setopt($ch, CURLOPT_URL, $searchURL . $searchString); | |
curl_setopt($ch, CURLOPT_USERAGENT,'Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.13) Gecko/20080311 Firefox/2.0.0.13'); | |
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); | |
curl_setopt($ch, CURLOPT_TIMEOUT, '10'); | |
$content = trim(curl_exec($ch)); | |
curl_close($ch); | |
// Quiet damn errors | |
libxml_use_internal_errors(true); | |
$html = new DOMDocument(); | |
$html->loadHTML($content); | |
$xpath = new DOMXPath( $html ); | |
$players = $xpath->query( '//*[contains(concat( " ", @class, " " ), concat( " ", "row", " " ))]//*[contains(concat( " ", @class, " " ), concat( " ", "columnName", " " ))]//span' ); | |
libxml_clear_errors(); | |
$playerArray = Array(); | |
foreach ($players as $player) { | |
$playerArray[] = $player->nodeValue; | |
} | |
$arrayPos = ($search % $perPage) - 1; | |
if ($arrayPos < 0) { | |
$arrayPos = $perPage - 1; | |
} | |
$playerName = preg_replace("/[^a-zA-Z]+/", " ", $playerArray[$arrayPos]); | |
// $addName = mysql_query("INSERT INTO names (name, active) VALUES ('$playerName', 1)"); | |
echo "INSERT INTO names (name, active) VALUES ('$playerName', 1)\n"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment