Jump to content

PHP Get funstion?


Evultoad

Recommended Posts

Im trying to pull some information from a website's table just need the one row from a table. Ive been searching around for about 3 hours now, and only leading to dead ends.

Im trying to get

<tr class="row rowp4">

this row from the website, im not entirely sure im meant to be using the GET command, or wether there are other commands?

I've also tried file_get_contents command, but im still not entirely sure what im doing

 

to give you a overview of what im trying to do:

im trying to pull highscores from a game's website and post to my own, and will look similar to this

Skills         Rank Level XP

Overall 170,434 1,732 49,722,114

 

the "Overall" line is

<tr class="row rowp4">

in the table

 

hope Ive given enough information so that you can see what im trying to do, if not leave a message and ill try my best to give more information.

Link to comment
Share on other sites

yea ive tried xpath

the code i currently have follows but the page just comes up blank

<title>Runescape Stats</title>

<?php

function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;

$allcont = file_get_contents_curl("http://services.runescape.com/m=hiscore/hiscorepersonal.ws?user1=Evultoad");


$Overall = $xpath->query('/html/body//tr[@class="row rowp1"]');
$Attack = $xpath->query('/html/body//tr[@class="row rowp2"]');
$Defence = $xpath->query('/html/body//tr[@class="row rowp3"]');
$Strength = $xpath->query('/html/body//tr[@class="row rowp4"]');
$Constitution = $xpath->query('/html/body//tr[@class="row rowp5"]');
$Ranged = $xpath->query('/html/body//tr[@class="row rowp6"]');
$Prayer = $xpath->query('/html/body//tr[@class="row rowp7"]');
$Magic = $xpath->query('/html/body//tr[@class="row rowp8"]');
$Cooking = $xpath->query('/html/body//tr[@class="row rowp9"]');
$Woodcutting = $xpath->query('/html/body//tr[@class="row rowp10"]');
$Fletching = $xpath->query('/html/body//tr[@class="row rowp11"]');
$Fishing = $xpath->query('/html/body//tr[@class="row rowp12"]');
$Firemaking = $xpath->query('/html/body//tr[@class="row rowp13"]');
$Crafting = $xpath->query('/html/body//tr[@class="row rowp14"]');
$Smithing = $xpath->query('/html/body//tr[@class="row rowp15"]');
$Mining = $xpath->query('/html/body//tr[@class="row rowp16"]');
$Herblore = $xpath->query('/html/body//tr[@class="row rowp17"]');
$Agility = $xpath->query('/html/body//tr[@class="row rowp18"]');
$Thieving = $xpath->query('/html/body//tr[@class="row rowp19"]');
$Slayer = $xpath->query('/html/body//tr[@class="row rowp20"]');
$Farming = $xpath->query('/html/body//tr[@class="row rowp21"]');
$Runecrafting = $xpath->query('/html/body//tr[@class="row rowp22"]');
$Hunter = $xpath->query('/html/body//tr[@class="row rowp23"]');
$Construction = $xpath->query('/html/body//tr[@class="row rowp24"]');
$Summoning = $xpath->query('/html/body//tr[@class="row rowp25"]');
$Dungeoneering = $xpath->query('/html/body//tr[@class="row rowp26"]');

echo '$Overall';}

?>

Link to comment
Share on other sites

Fatal error: Call to a member function query() on a non-object in rune.php on line 17

 

new code changed to

function file_get_contents_curl($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_URL, $url);
$data = curl_exec($ch);
curl_close($ch);
return $data;
}

 

line 17:

$Overall = $xpath->query('/html/body//tr[@class="row rowp1"]');

Link to comment
Share on other sites

ive managed to re-write the script, but theres no format to it at all its all listed on to one continuous line

this is hte code ive code so far

<title>Runescape Stats</title>

<?php

$xx = "http://services.runescape.com/m=hiscore/hiscorepersonal.ws?user1=Evultoad";
$cURL = curl_init();

curl_setopt($cURL, CURLOPT_URL, $xx);
curl_setopt($cURL, CURLOPT_HEADER,0);


curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL, CURLOPT_COOKIESESSION, true);
curl_setopt($cURL, CURLOPT_FOLLOWLOCATION, 1);
$strPage = curl_exec($cURL);
curl_close($cURL);

list($a,$b,$c,$d,$e,$f,$g,$h,$i)=split("<tbody>",$strPage );

print_r($b);

?>

Link to comment
Share on other sites

just incase anyone is interested i have been helped out and have a working script now

<title>Runescape Stats</title>

<?php

$xx = "http://services.runescape.com/m=hiscore/hiscorepersonal.ws?user1=Evultoad";
$cURL = curl_init();

curl_setopt($cURL, CURLOPT_URL, $xx);
curl_setopt($cURL, CURLOPT_HEADER,0);

curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL, CURLOPT_COOKIESESSION, true);
curl_setopt($cURL, CURLOPT_FOLLOWLOCATION, 1);
$strPage = curl_exec($cURL);
curl_close($cURL);

$Overall = '#<tr class="row rowp1">(.+)</tr>#Us';
if( preg_match($Overall, $strPage, $match) ){
    $catch = $match[1];
    echo '<table border="1"><tr>';
    echo $catch;
    echo '</tr></table>';
}else{
    echo 'No result in highcores';
}

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.