`Karl Posted November 13, 2009 Share Posted November 13, 2009 Well, I need to grab data from another website, which isn't my own. I've already contacted the website to see if I could have permission to screen scrape, however, they declined so I'm looking for an alternative way. An example of a page I want to get information from can be seen here: http://services.runescape.com/m=itemdb_rs/Abyssal_whip/viewitem.ws?obj=4151 The information I need is: 3.4m, 3.6m and 3.8m Any input would be appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/ Share on other sites More sharing options...
sKunKbad Posted November 13, 2009 Share Posted November 13, 2009 You would want to use file_get_contents or similar function, and then search for: <span> <b>Minimum price:</b> 3.4m </span> <span class="spaced_span"> <b>Market price:</b> 3.6m </span> <span> <b>Maximum price:</b> 3.8m </span> replacing the numbers with regular expressions for float type numbers, which would be part of a callback to retrieve that actual data. I don't know if this is the most efficient way of doing it, but it's all I could think of. Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957102 Share on other sites More sharing options...
`Karl Posted November 13, 2009 Author Share Posted November 13, 2009 Mmm, I'll have a look in to it. Edit: Can't figure it out >.< Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957129 Share on other sites More sharing options...
`Karl Posted November 13, 2009 Author Share Posted November 13, 2009 Anyone have any other ideas? Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957143 Share on other sites More sharing options...
`Karl Posted November 13, 2009 Author Share Posted November 13, 2009 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957152 Share on other sites More sharing options...
sKunKbad Posted November 13, 2009 Share Posted November 13, 2009 Without studying a bit on regular expressions, your not likely to figure it out, but the function that I would try to use on the data obtained from file_get_contents would be preg_match. See the preg_match page in the docs to see usage, and then go over to the regular expressions forum to see if you are doing it right. Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957161 Share on other sites More sharing options...
`Karl Posted November 14, 2009 Author Share Posted November 14, 2009 Any way you can push me in the right direction? <?php $data = file_get_contents('http://services.runescape.com/m=itemdb_rs/Abyssal_whip/viewitem.ws?obj=4151'); $regex = '/Minimum Price:<\/b> (.+?)<\/span>/'; preg_match($regex,$data,$match); var_dump($match); echo $match[1]; ?> Returns: array(0) { } Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957174 Share on other sites More sharing options...
`Karl Posted November 14, 2009 Author Share Posted November 14, 2009 Okay, so I had a mess around and got it working, however, when I tried to change it so that a user must use a form and type in an item number, it just comes back blank. <?php $itemnumber = $_GET['itemnumber']; $lookup = $_POST['lookup']; $minimum = explode('<b>Minimum price:</b> ',$content); $minimum2 = explode('</span>',$minimum[1]); $minimumprice = $minimum2[0]; $current = explode('<b>Market price:</b> ',$content); $current2 = explode('</span>',$current[1]); $currentprice = $current2[0]; $maximum = explode('<b>Maximum price:</b> ',$content); $maximum2 = explode('</span>',$maximum[1]); $maximumprice = $maximum2[0]; ?> <form action="" method="POST"> <input type="text" name="itemnumber" /> <input type="submit" value="Lookup" name="lookup" /> </form> <?php if(isset($_POST['lookup'])) { $content = file_get_contents('http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=' . $itemnumber); echo 'Minimum Price: ' . $minimumprice; echo '<br>'; echo 'Market Price: ' . $currentprice; echo '<br>'; echo 'Maximum Price: ' . $maximumprice; unset($content,$minimum,$minimum2,$current,$current2,$maximum,$maximum2); } ?> If a user puts in 4151 in to the box, which is a valid item. Then the Minimum Price all return blank, when they should in fact return the prices. Whereas this works perfectly and returns the data: <?php $content = file_get_contents('http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=4151'); $minimum = explode('<b>Minimum price:</b> ',$content); $minimum2 = explode('</span>',$minimum[1]); $minimumprice = $minimum2[0]; $current = explode('<b>Market price:</b> ',$content); $current2 = explode('</span>',$current[1]); $currentprice = $current2[0]; $maximum = explode('<b>Maximum price:</b> ',$content); $maximum2 = explode('</span>',$maximum[1]); $maximumprice = $maximum2[0]; echo 'Minimum Price: ' . $minimumprice; echo '<br>'; echo 'Market Price: ' . $currentprice; echo '<br>'; echo 'Maximum Price: ' . $maximumprice; unset($content,$minimum,$minimum2,$current,$current2,$maximum,$maximum2); ?> Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957211 Share on other sites More sharing options...
trq Posted November 14, 2009 Share Posted November 14, 2009 Didn't you just say they declined to allow you to do this? Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957214 Share on other sites More sharing options...
`Karl Posted November 14, 2009 Author Share Posted November 14, 2009 Indeed I did, but there are other communities that do the same thing. My guess is they didn't ask and no one came up with another method to retrieve the data. I was only declined as it would take up a lot of server resources on their end. If there's a method to make that server load smaller then they'd allow it. If you know of a method, please, enlighten me. Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957215 Share on other sites More sharing options...
trq Posted November 14, 2009 Share Posted November 14, 2009 Indeed I did, but there are other communities that do the same thing Ahh, right, I guess that makes it ok then. Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957217 Share on other sites More sharing options...
`Karl Posted November 14, 2009 Author Share Posted November 14, 2009 Don't try to be sarcastic, the communities I'm talking about are recognised fansites by the creators of the game. Even websites which are not recognised use this method. I'm also guessing by your response that you do not know of an alternative method. Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957218 Share on other sites More sharing options...
trq Posted November 14, 2009 Share Posted November 14, 2009 I'm also guessing by your response that you do not know of an alternative method. There is no alternate method unless you get permission to get the data directly from there database. Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957222 Share on other sites More sharing options...
`Karl Posted November 14, 2009 Author Share Posted November 14, 2009 Any idea why my code returns blank when I can see nothing wrong with it? Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957223 Share on other sites More sharing options...
joel24 Posted November 14, 2009 Share Posted November 14, 2009 an ethical error maybe? Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957265 Share on other sites More sharing options...
joel24 Posted November 14, 2009 Share Posted November 14, 2009 you've got your PHP all jumbled up.. you're calling to fetch the page from the server after you try to read it... <?php if(isset($_POST['lookup'])) { $itemnumber = $_GET['itemnumber']; $content = file_get_contents('http://services.runescape.com/m=itemdb_rs/viewitem.ws?obj=' . $itemnumber); $lookup = $_POST['lookup']; $minimum = explode('<b>Minimum price:</b> ',$content); $minimum2 = explode('</span>',$minimum[1]); $minimumprice = $minimum2[0]; $current = explode('<b>Market price:</b> ',$content); $current2 = explode('</span>',$current[1]); $currentprice = $current2[0]; $maximum = explode('<b>Maximum price:</b> ',$content); $maximum2 = explode('</span>',$maximum[1]); $maximumprice = $maximum2[0]; } ?> <form action="" method="POST"> <input type="text" name="itemnumber" /> <input type="submit" value="Lookup" name="lookup" /> </form> <?php if(isset($_POST['lookup'])) { echo 'Minimum Price: ' . $minimumprice; echo '<br>'; echo 'Market Price: ' . $currentprice; echo '<br>'; echo 'Maximum Price: ' . $maximumprice; unset($content,$minimum,$minimum2,$current,$current2,$maximum,$maximum2); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-957268 Share on other sites More sharing options...
sKunKbad Posted November 26, 2009 Share Posted November 26, 2009 I'm also guessing by your response that you do not know of an alternative method. If anyone would know an alternate method, it would be thorpe. Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-965737 Share on other sites More sharing options...
oni-kun Posted November 26, 2009 Share Posted November 26, 2009 Any idea why my code returns blank when I can see nothing wrong with it? Your code obviously is not ethical. Data theft is wrong, You could get the mob after you! Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-965751 Share on other sites More sharing options...
corrupshun Posted November 26, 2009 Share Posted November 26, 2009 How is this unethical?? WOW Quote Link to comment https://forums.phpfreaks.com/topic/181436-solved-grab-data-from-another-website/#findComment-965783 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.