young_coder Posted July 15, 2010 Share Posted July 15, 2010 Dear all, Can somebody help me to modify this script to scrape more than just one page? Thank you very much advance. <?php $url = "http://www.example.com"; $fp = fopen( $url, ‘r’ ); $content = ""; while( !feof( $fp ) ) { $buffer = trim( fgets( $fp, 4096 ) ); $content .= $buffer; } $start = '<title>'; $end = '<\/title>'; preg_match( "/$start(.*)$end/s", $content, $match ); $title = $match[ 1 ]; $metatagarray = get_meta_tags( $url ); $keywords = $metatagarray[ "keywords" ]; $description = $metatagarray[ "description" ]; echo "<div><strong>URL:</strong> $url</div>\n"; echo "<div><strong>Title:</strong> $title</div>\n"; echo "<div><strong>Description:</strong> $description</div>\n"; echo "<div><strong>Keywords:</strong> $keywords</div>\n"; ?> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted July 15, 2010 Share Posted July 15, 2010 Put the URLs you want to scrape in an array and loop through the array. Also if you use file_get_contents, your script will look cleaner: <?php $urls = array('http://www.example.com/','http://www.example.org/','http://www.example.net/'); $start = '<title>'; $end = '<\/title>'; foreach ($urls as $url) { $content = file_get_contents($url); preg_match( "/$start(.*)$end/s", $content, $match ); $title = $match[1]; $metatagarray = get_meta_tags($url); $keywords = $metatagarray['keywords']; $description = $metatagarray['description']; echo "<div><span style='font-weight:bold'>URL:</span> $url</div>\n"; echo "<div><span style='font-weight:bold'>Title:</span> $title</div>\n"; echo "<div><span style='font-weight:bold'>Description:</span> $description</div>\n"; echo "<div><span style='font-weight:bold'>Keywords:</span> $keywords</div>\n"; } ?> Ken Quote Link to comment Share on other sites More sharing options...
young_coder Posted July 16, 2010 Author Share Posted July 16, 2010 Thank you kenrbnsn Quote Link to comment 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.