Page 1 of 1

Finding number of Yahoo and MSN search results with regex?

Posted: Tue Aug 24, 2004 10:49 am
by MatthewForshaw
Hi all,

I'm trying to write a function that'll get the number of results for a particular search on Google, MSN and Yahoo. Google is all sorted and you can check the code below but I cant seem to get it to work for the other two search engines.

Code: Select all

$request = file_get_contents("http://www.google.com/search?q=site:" . $site);
preg_match("/\Results <b>&#1111;0-9,]+<\/b> - <b>&#1111;0-9,]+<\/b> of (about )?<b>(&#1111;0-9,]+)<\/b>/i", $request, $matches);
echo "Saturation: ".$matches&#1111;2]."<br>";
If anyone can help me figure it out for the other two it'd be great. Might be a small token of my appreciation for the person(s) who manage to figure it out.

Thanks,
Matt

Posted: Tue Aug 24, 2004 11:02 am
by feyd
what code do you have so far for the others?


we aren't going to do it for you

Posted: Tue Aug 24, 2004 11:05 am
by MatthewForshaw
Nothing that seems to work so far. Here are the HTML strings that I need to use. I've tried doing the common-sense thing by experimenting but i'm not having much luck.

Yahoo:

Code: Select all

<h1>Search Results</h1><p>Results <strong>1 - 20</strong> of about <strong>340,000</strong>
MSN

Code: Select all

Results 1-15 of about 63154

Posted: Tue Aug 24, 2004 11:13 am
by feyd
does all: untested

Code: Select all

preg_match('#results.+?[0-9,]+?.+?[0-9,]+?of.+?([0-9,]+)#i',$request,$matches)

Posted: Tue Aug 24, 2004 11:22 am
by MatthewForshaw
Thanks. I've given it a try but I don't seem to be able to get it to work. No errors, nothing's being outputted though. Here's my usage:

Code: Select all

$site = "http://www.devnetwork.net";
$request = file_get_contents("http://search.msn.com/results.aspx?FORM=MSNH&q=site:" . $site);
preg_match('#results.+?&#1111;0-9,]+?.+?&#1111;0-9,]+?of.+?(&#1111;0-9,]+)#i',$request,$matches);
echo "m Saturation: ".$matches&#1111;2]."<br>";
Thanks

Posted: Tue Aug 24, 2004 11:35 am
by feyd
the data would be under $matches[1] if they existed..

Posted: Tue Aug 24, 2004 12:28 pm
by MatthewForshaw
Thanks 10x, with a little mod its all working great. Cheers!