Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Images Indexed In Search Engines

Posted on 2006-04-24
12
Medium Priority
?
201 Views
Last Modified: 2006-11-18
Hello all!

Is it possible to create a script that checks and displays how many images are indexed for a list of URLs (domains)?

So if I had a list like:

http://url1
http://url2
http://url3

The script would check both "Yahoo image search" and "Google image search" and return how many images each domain has indexed - like:

url1= 12 Yahoo 10 Google
url2= 2 Yahoo 5 Google
url3= 15 Yahoo 12 Google


Is this at all possible??

Thank you~!
0
Comment
Question by:laura_sky
  • 6
  • 4
10 Comments
 
LVL 8

Expert Comment

by:KennyTM
ID: 16532605
function get_google_search_count ($q) {
  $s = file_get_contents('http://images.google.com/images?q=' . urlencode($q));
  $b = preg_match ('|Results <b>1</b> - <b>\d+</b> of(?: about)? <b>([\d,]+)</b>|', $s, $a);
  return $b ? intval(str_replace(',', '', $a[1])) : 0;
}

echo get_google_search_count('Radiation'); // outputs 266000
0
 
LVL 8

Expert Comment

by:KennyTM
ID: 16532608
To get the count for a specific site, use

echo get_google_search_count('site:www.experts-exchange.com'); // outputs 103
0
 
LVL 8

Expert Comment

by:KennyTM
ID: 16532668
function get_image_search_count ($q, $engine) {
$engine_url = Array(
  'google' => 'http://images.google.com/images?q=',
  'yahoo' => 'http://images.search.yahoo.com/search/images?p=',
  'msn' => 'http://search.msn.com/images/results.aspx?q='
);
$engine_regex = Array (
  'google' => '#Results <b>1</b> - <b>\d+</b> of(?: about)? <b>([\d,]+)</b>#',
  'yahoo' => '#Results <strong>1 - \d+</strong> of about <strong>([\d,]+)</strong>#',
  'msn' => '#<h5>Page 1 of ([\d,]+) results containing#'
);
  $e = strtolower($engine);
  $s = file_get_contents( $engine_url[$e] . urlencode($q) );
  $b = preg_match ($engine_regex[$e], $s, $a);
  return $b ? intval(str_replace(',', '', $a[1])) : 0;
}

echo get_image_search_count('Hello world!', 'Yahoo') . '<br />';  // 73331
echo get_image_search_count('Hello world!', 'Google') . '<br />'; // 73800
echo get_image_search_count('Hello world!', 'MSN') . '<br />';    // 2176
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

Author Comment

by:laura_sky
ID: 16538004
Thanks KennyTM . . .

If I wanted to use a textarea box to enter a list of URLs, how would I do this?

Like:

<form action="index.php>
<textarea>
http://url1
http://url2
http://url2
</textarea>
<input type="submit" value="Check">
</form>

Is there a way to do this, so that it checks each URL from the list?

Thanks~!
0
 
LVL 8

Expert Comment

by:KennyTM
ID: 16550427
The problem is that Yahoo! will not search anything if you enter only the domain alone. (e.g., in http://images.search.yahoo.com/search/images/advanced?ei=UTF-8 , enter some URL in "only search in this domain/site:" and leave all other things blank, then press "Yahoo! Search"... you'd end up being in the homepage of image search.)
0
 

Author Comment

by:laura_sky
ID: 16550487
I see what you're saying...

In that case, how about using GET, and appending the domain to the end of:

http://images.search.yahoo.com/search/images?ei=UTF-8&x=wrt&p=experts-exchange.com

Which returns 70 results...

If this still won't work, is there a way to just check Google image search?

Also, is it possible to check a list of URLs enetered into a textarea field?

Thanks~!
0
 
LVL 8

Expert Comment

by:KennyTM
ID: 16550993
If you just want to check the Google image search, just write

get_image_search_count('site:www.experts-exchange.com', 'Google');

----

For your suggestion, it can actually be implemented with

get_image_search_count('experts-exchange.com', 'Yahoo');

However, as you can see from the result, not everything is really related by experts-exchange.com. For example, the first image "headleft.jpg" has absolutely nothing to do with experts-exchange.com (although the URL www.force137.com/forum/showthread.php?t=7593 has the string "experts-exchange.com"). If this is what you want, just use the code above. Otherwise, I can't help with Yahoo!.
0
 

Author Comment

by:laura_sky
ID: 16555072
Ok, I see...

But how would I check a list of URLs at the same time without entering them each individually?

With:

get_image_search_count('site:www.experts-exchange.com', 'Google');

I would have to type in the URL for each site, which would be very time consuming, and would defeat the purpose of creating a script in the first place. :-)

So can a textarea field be used?

Thanks~!
0
 
LVL 8

Accepted Solution

by:
KennyTM earned 1600 total points
ID: 16555214
sure. Suppose $a holds the content of the textarea. Then you explode() the string by

$urls = explode("\r\n", $a);

Then call get_image_search_count() for every URL:

$counts = Array();
foreach ($urls as $k => $url) {
  $counts[$k] = get_image_search_count("site:$url", 'Google');
}
print_r ($counts);
0
 

Author Comment

by:laura_sky
ID: 16746626
I'm sorry, I've been so busy recently that I totally forgot about this question!

I have not abandoned this question. In fact, I still require help with this question, that is if KennyTM still wants to assist me?

If not, I will gladly close this question and award KennyTM 400 points.

Please let me know!

Thanks again!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this. Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it i…
Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses
Course of the Month20 days, 19 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question