ExSpirit Posted September 4, 2010 Share Posted September 4, 2010 I am wondering if it's possible to get some data from another website via PHP? I would like to get data from website http://www.gamersfirst.com/warrock/?q=Player&nickname=soldier, and the exact data which I need is "Level" which is in this case 2. Can this value be grabbed and if it can, where can I get some info about how to do it? Quote Link to comment https://forums.phpfreaks.com/topic/212545-get-specific-data-from-another-website/ Share on other sites More sharing options...
freeloader Posted September 4, 2010 Share Posted September 4, 2010 Sure, it's possible. Could be done in a number of ways, the easiest (for me) is cURL. You could however also use DOMDocument. Then you'd have to do a regex on the page source and get the values you need. I'd give you an example on the site you just gave, but when I'm loading it, I get the following error: You may have mis-typed the URL. Please check your spelling. Quote Link to comment https://forums.phpfreaks.com/topic/212545-get-specific-data-from-another-website/#findComment-1107302 Share on other sites More sharing options...
ExSpirit Posted September 4, 2010 Author Share Posted September 4, 2010 Ups, the comma at the end of URL is not needed, so url is - http://www.gamersfirst.com/warrock/?q=Player&nickname=soldier I was reading a few tutorials about curl but couldn't get much progress.. Quote Link to comment https://forums.phpfreaks.com/topic/212545-get-specific-data-from-another-website/#findComment-1107308 Share on other sites More sharing options...
freeloader Posted September 4, 2010 Share Posted September 4, 2010 cURL is pretty simple though, basic examples are here: http://curl.haxx.se/libcurl/php/examples/simpleget.html Rough draft, didn't test it: <?php $CurlStart = curl_init(); curl_setopt ($CurlStart, CURLOPT_URL, "http://www.gamersfirst.com/warrock/?q=Player&nickname=soldier"); curl_setopt ($CurlStart, CURLOPT_HEADER, 0); $source = curl_exec ($CurlStart); curl_close ($CurlStart); $a=preg_match("/Level:</td>\n.*.<td>([0-9]+)</",$source,$b); $Level = $b[2]; ?> Quote Link to comment https://forums.phpfreaks.com/topic/212545-get-specific-data-from-another-website/#findComment-1107311 Share on other sites More sharing options...
ExSpirit Posted September 4, 2010 Author Share Posted September 4, 2010 I tried this code and I get this error: Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. ... Warning: preg_match() [function.preg-match]: Unknown modifier 't' in /home/content/test.php on line 8 Quote Link to comment https://forums.phpfreaks.com/topic/212545-get-specific-data-from-another-website/#findComment-1107318 Share on other sites More sharing options...
freeloader Posted September 4, 2010 Share Posted September 4, 2010 Ya, written in 2 secs with an obvious mistake there Your regex should be: $a=preg_match("/Level:<\/td>\n.*.<td>([0-9]+)</",$source,$b); Try again using that. Quote Link to comment https://forums.phpfreaks.com/topic/212545-get-specific-data-from-another-website/#findComment-1107322 Share on other sites More sharing options...
ExSpirit Posted September 4, 2010 Author Share Posted September 4, 2010 The bottom error is gone, but the internal Server Error is still there... I have no idea why... Internal Server Error The server encountered an internal error or misconfiguration and was unable to complete your request. Please contact the server administrator, webmaster@localhost and inform them of the time the error occurred, and anything you might have done that may have caused the error. More information about this error may be available in the server error log. Apache/2.2.11 (Ubuntu) Server at www.gamersfirst.com Port 80 Quote Link to comment https://forums.phpfreaks.com/topic/212545-get-specific-data-from-another-website/#findComment-1107324 Share on other sites More sharing options...
freeloader Posted September 4, 2010 Share Posted September 4, 2010 <?php $CurlStart = curl_init(); curl_setopt ($CurlStart, CURLOPT_URL, "http://www.gamersfirst.com/warrock/?q=Player&nickname=soldier"); curl_setopt ($CurlStart, CURLOPT_RETURNTRANSFER, 1); curl_setopt ($CurlStart, CURLOPT_REFERER, $url); curl_setopt ($CurlStart, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 6.1; nl; rv:1.9.1.11) Gecko/20100701 Firefox/3.5.11"); curl_setopt ($CurlStart, CURLOPT_HEADER, 1); curl_setopt ($CurlStart, CURLOPT_FOLLOWLOCATION, true); $source = curl_exec ($CurlStart); curl_close ($CurlStart); $a=preg_match("/>Level:.*.\n.*.>([0-9]*)</",$source,$b); $Level = $b[1]; echo "Level: $Level"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/212545-get-specific-data-from-another-website/#findComment-1107326 Share on other sites More sharing options...
ExSpirit Posted September 4, 2010 Author Share Posted September 4, 2010 freeloader you rock This works like a charm now. Thank you very much! Quote Link to comment https://forums.phpfreaks.com/topic/212545-get-specific-data-from-another-website/#findComment-1107327 Share on other sites More sharing options...
ExSpirit Posted September 6, 2010 Author Share Posted September 6, 2010 I managed to get most of the data, but now I'm a bit stuck at a few values: Clan Name (uses href) Clan Tag Recruitment (uses span) Beside that if Clan name or tag is empty then the code shows me input box - probably because there's another "Clan tag" and "Clan name:" in code which has input field after... To get better view of the code you should check THIS LINK, where all fields are checked. Can you help me how to get those values? Quote Link to comment https://forums.phpfreaks.com/topic/212545-get-specific-data-from-another-website/#findComment-1107947 Share on other sites More sharing options...
samcrime786 Posted September 18, 2010 Share Posted September 18, 2010 Hi. Beside getting the data from other websites you can change the name or tag is empty then the code shows me input box. I agree to this term.. _______________________________________________________________________ Earn an Extra $1000 to $1200 per month doing Part Time Data Entry Jobs! Work from home data entry jobs to post simple data submissions on Internet. Make $1 per entry. Easy form filling, data entry and ad posting jobs. No selling, No phone calls, No Marketing. No Investment. Bi-weekly payments. Full Training Provided. Pls visit: Data-Entry Quote Link to comment https://forums.phpfreaks.com/topic/212545-get-specific-data-from-another-website/#findComment-1112392 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.