Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LInk Popularity 1

Status
Not open for further replies.

sulfericacid

Programmer
Joined
Aug 15, 2001
Messages
244
Location
US
Can someone show me the basics into designing a link popularity script? Link popularity is the number of times your url is found on a specific search engine.

I was wondering if someone could create a small script that searches one search engine for a url and post the results in the next page. The results should be the number of times it is found.

Can someone help?

Thanks!

-Acid
 
I guess one way of going about doing this is:

(this searches Altavista for as the URL which in turn, the number of results is the popularity)

#!/usr/local/bin/perl

$|=1;

require LWP::UserAgent;
$url_to_find = "
# search altavista to find out what the
# popularity is for $url_to_find
$URL = "
# initiate UserAgent and Headers for URI request
$ua = new LWP::UserAgent;
$h = new HTTP::Headers;
# set request timeout to 50 seconds
$ua->timeout(50);
$c = "";

$request = new HTTP::Request('GET', $URL, $h, $c);

#send request
$response = $ua->request($request);
#get response
$tResponse = $response->content;

#split prior to result count
@split1 = split("We found",$tResponse);
#split post to result count
@split2 = split("results",$split1[1]);
#result count is first item in second split
$results = $split2[0];

print "Content-type: text/html\n\n";
print $results;


chad. ICQ: 54380631
online.dll
 
Thanks billions for your codes. I have not tried it yet, but I am sure it works. I know you must have put some time into doing that and that makes what I have to ask perhaps a monumental favor. Could you explain what is happening in the script? I have been studying perl for a few months and I am unfamilar with most of it.

Thanks in advance and thanks for the codes!

-Acid
 
Hey Chad

I tried your script and it works smoothly mate..

And sulfericacid, there is a time when you're ment to learn things for yourself.. Get yourself a good O'reilly perl book and just work through it.. you'll learn it in no time, and you'll have learnt it properly.. Learning by example is the best way to learn, and actually getting in there and writing your own code from examples is a GREAT way to learn...

just my two bits.. :) /-------------------------------------
| I always have been, and
| always will be, a newbie :)
\-------------------------------------
 
sulfericacid,

I have commented the code in my post for you to study. Basically, most of the code is utilization (instantiation and methods) from LWP and HTTP modules.

You can just go to and do a search for these and study the READMEs or you can go to a terminal on *nix that has these modules and read the perldoc or man pages for them.

The rest is actually very generic use of split() to pull out the content that we want. One could even just do a regular expression to get this content, something like the following (most likely wrong though):

$results =~ /^(.+We found)(.+)(Results.+)$/\\2/i

ICQ: 54380631
online.dll
 
Sorry, actually, the replacement would be $2 not \\2

$results =~ /(.+We found)(.+)(Results.+)/$2/gi ICQ: 54380631
online.dll
 
I thank you BILLIONS for all your guys' help. I am sorry I have not been responding to your replies but I have not been getting emails saying that anyone responded. I guess it is partially my fault for not checking back. Again, thanks BILLIONS!

Aaron
 
This seems to work fine except that it gives results as only "2" for tilde URLs. Just the number 2 on the screen but nothing else. With a non-tilde URL, it works just as it should. How can this be tweeked to work with a tilde-URL? Don
pc@accesscom.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT (only when I have to!)
 
make sure to urlencode your url.

chad.

;-) ICQ: 54380631
online.dll
 
Actually, the "2" appears to be the be the number of results. It seems that it will show only one. I tried several different URLs without a tilde and got different numbers for each. Don
pc@accesscom.com
Experienced in HTML, Perl, VBScript, PWS, IIS and Apache. Run OS/2 Warp 4, BeOS v5 and Windows NT (only when I have to!)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top