Finding number of Yahoo and MSN search results with regex?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
MatthewForshaw
Forum Newbie
Posts: 4
Joined: Tue Aug 24, 2004 10:49 am

Finding number of Yahoo and MSN search results with regex?

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

what code do you have so far for the others?


we aren't going to do it for you
MatthewForshaw
Forum Newbie
Posts: 4
Joined: Tue Aug 24, 2004 10:49 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

does all: untested

Code: Select all

preg_match('#results.+?[0-9,]+?.+?[0-9,]+?of.+?([0-9,]+)#i',$request,$matches)
MatthewForshaw
Forum Newbie
Posts: 4
Joined: Tue Aug 24, 2004 10:49 am

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the data would be under $matches[1] if they existed..
MatthewForshaw
Forum Newbie
Posts: 4
Joined: Tue Aug 24, 2004 10:49 am

Post by MatthewForshaw »

Thanks 10x, with a little mod its all working great. Cheers!
Post Reply