Evultoad Posted April 15, 2010 Share Posted April 15, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/ Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 I suggest cURL. Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042589 Share on other sites More sharing options...
Evultoad Posted April 15, 2010 Author Share Posted April 15, 2010 in what way should it be used? Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042592 Share on other sites More sharing options...
Evultoad Posted April 15, 2010 Author Share Posted April 15, 2010 ive managed to pull the entire page from the website using curl i just need to find out out to pull certain rows from table and leave the rest of the website out Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042604 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 Okay, I don't know what the site looks like so here are some functions that should help you get what you want: match via regular expression preg_match preg_match_all break up a string explode You may not need all of them, but they should get the job done. Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042612 Share on other sites More sharing options...
Maq Posted April 15, 2010 Share Posted April 15, 2010 Depending on how/what you're trying to get, XPath might be better: http://us2.php.net/simplexml http://us2.php.net/dom Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042622 Share on other sites More sharing options...
Evultoad Posted April 15, 2010 Author Share Posted April 15, 2010 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';} ?> Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042642 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 You're missing a closing brace } in your function. Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042644 Share on other sites More sharing options...
Evultoad Posted April 15, 2010 Author Share Posted April 15, 2010 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"]'); Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042649 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 What is $xpath defined as? Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042650 Share on other sites More sharing options...
Evultoad Posted April 15, 2010 Author Share Posted April 15, 2010 omg, didnt even notice that, however im not too sure what to define it as so it pulls the specified table information down, any suggestions? Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042653 Share on other sites More sharing options...
Ken2k7 Posted April 15, 2010 Share Posted April 15, 2010 Try this: $xpath = new SimpleXMLElement($allcont); Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042655 Share on other sites More sharing options...
Evultoad Posted April 15, 2010 Author Share Posted April 15, 2010 whole load of errors from that Warning: SimpleXMLElement::__construct() [simplexmlelement.--construct]: Entity: line 38: parser error : Opening and ending tag mismatch: meta line 32 Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042659 Share on other sites More sharing options...
Evultoad Posted April 15, 2010 Author Share Posted April 15, 2010 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); ?> Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042698 Share on other sites More sharing options...
Evultoad Posted April 16, 2010 Author Share Posted April 16, 2010 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'; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/198673-php-get-funstion/#findComment-1042778 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.