unknown101 Posted April 17, 2008 Share Posted April 17, 2008 Hi Guys, Just wondering if theres any working sample code or tutorials around on extracting data from a given webpage URL. I have searched google, but nothing particularly great has appeared. Basically I want to search a bunch of given URL's for key words and if they are found return data to a text file, any help is appreciated.. Thanks in advance Link to comment https://forums.phpfreaks.com/topic/101571-extracting-data-from-a-website/ Share on other sites More sharing options...
discomatt Posted April 17, 2008 Share Posted April 17, 2008 Easy enough... first question though, does your production server have fopen wrappers turned on? Link to comment https://forums.phpfreaks.com/topic/101571-extracting-data-from-a-website/#findComment-519546 Share on other sites More sharing options...
unknown101 Posted April 17, 2008 Author Share Posted April 17, 2008 Yep it does. Link to comment https://forums.phpfreaks.com/topic/101571-extracting-data-from-a-website/#findComment-519568 Share on other sites More sharing options...
discomatt Posted April 17, 2008 Share Posted April 17, 2008 Here's a basic version of what you wanna do <?php // What do you wanna search for? $search = 'PHP'; // Grab the source to a string $source = file_get_contents('http://www.phpfreaks.com/forums/'); // Basic version if ( stripos($source, $search) ) echo 'The website grabbed has '. $search .' in it'; echo '<br>'; // With a little more filtering $count = substr_count( strtoupper($source), strtoupper($search) ); if ($count > 5) echo 'The website grabbed has '. $search .' in it more than 5 times'; ?> Link to comment https://forums.phpfreaks.com/topic/101571-extracting-data-from-a-website/#findComment-519583 Share on other sites More sharing options...
unknown101 Posted April 17, 2008 Author Share Posted April 17, 2008 Hey, thanks for the code..Ill have a go with it shortly! Link to comment https://forums.phpfreaks.com/topic/101571-extracting-data-from-a-website/#findComment-519690 Share on other sites More sharing options...
unknown101 Posted April 19, 2008 Author Share Posted April 19, 2008 Hey there ive tested the code, seems just what i need as a starting point. But i now need to develop it slighly further. Basically I want to read values from a file, then search for these and the results which have been found returned to another text file. So am I correct in saying the process would be: Open file, find first value say "music", assign this to the $search variable, run the script though, print result to a txt file if its been found i.e. The word "music" has been found" within the URL. Then loop through this process reading in each value from the file until all have been searched? Thanks in advance. Link to comment https://forums.phpfreaks.com/topic/101571-extracting-data-from-a-website/#findComment-521359 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.