David Nelson Posted May 14, 2008 Share Posted May 14, 2008 Hey guys, I'm using a script to scrape Google images (http://blogoscoped.com/archive/2007-03-19-n36.html), you can take his source code there to look at it, but the problem is in his code it only displays the first result from the Google images results page -- however, his demo (http://blogoscoped.com/temp/google-image-scraper-2007.html) he setup does the entire first page of Google image results, but he doesn't explain how to do it. I've messed with it alot and can't figure out what is in that code that you could modify to make it display multiple results. I've attached the code below; (btw, this script essentially scrapes from http://images.google.com/images?hl=en&q=horses&btnG=Search+Images&gbv=2 or whatever you input as the variable, [his demo is 'horses'], in case you didn't get what I'm talking about) Thanks guys! <? $results = getGoogleImages('horses'); foreach ($results as $result) { echo '<p><a href="' . htmlentities($result['url']) . '">' . '<img src="' . htmlentities($result['thumbnail']) . '" alt="" ' . 'oncontextmenu="this.src=\'' . htmlentities($result['image']) . '\';return false;" ' . 'style="border: 1px solid black" /></a><br />' . '<em>' . htmlentities($result['description']) . '</em>' . '</p>'; } ?> </body> </html><? function getGoogleImages($q, $doSafeSearch = false) { $results = array(); $safe = ($doSafeSearch) ? 'on' : 'off'; $url = 'http://images.google.com/images?safe=' . $safe . '&q=' . urlencode($q); $result = file_get_contents($url); $from = 'dyn.Img("'; $startPos = strPos($result, $from); $endPos = strPos($result, ');dyn.updateStatus'); $functions = substr( $result, $startPos + strlen($from), $endPos ); $functions = explode('");dyn.Img("', $functions); foreach ($functions as $f) { $i = count($results); list($results[$i]['url'], $v1, $hash, $results[$i]['image'], $results[$i]['width'], $results[$i]['height'], $results[$i]['description'], $v2, $v3, $more, $extension, $domain) = explode('","', $f); list($results[$i]['url'], $params) = explode('&h', $results[$i]['url']); $prefix = 'http://tbn0.google.com/images?q=tbn:'; $results[$i]['thumbnail'] = $prefix . $hash . ':' . $results[$i]['image']; $results[$i]['description'] = strip_tags($results[$i]['description']); } return $results; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/105533-php-script-setup-for-multiple-readouts-only-outputs-one/ Share on other sites More sharing options...
David Nelson Posted May 15, 2008 Author Share Posted May 15, 2008 Hey guys, anybody? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/105533-php-script-setup-for-multiple-readouts-only-outputs-one/#findComment-541467 Share on other sites More sharing options...
MadTechie Posted May 15, 2008 Share Posted May 15, 2008 update $functions = explode('");dyn.Img("', $functions); to $functions = explode('",[]);dyn.Img(', $functions); should fix it Quote Link to comment https://forums.phpfreaks.com/topic/105533-php-script-setup-for-multiple-readouts-only-outputs-one/#findComment-541471 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.