Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Extract Host, Logical Host from URL

by downer (Monk)
on Aug 14, 2007 at 16:25 UTC ( #632539=perlquestion: print w/ replies, xml ) Need Help??
downer has asked for the wisdom of the Perl Monks concerning the following question:

I am searching for an easy way to accomplish this. The host part is easy, just what comes between http:// and the next /. however logical host seems to be tricky. for instance, shopping.yahoo.com and yahoo.com should both get mapped to the same logical host, yahoo.com. Is there a module that does this? perhaps a set of heuristics which could be used?

Comment on Extract Host, Logical Host from URL
Re: Extract Host, Logical Host from URL
by Fletch (Chancellor) on Aug 14, 2007 at 18:00 UTC

    Erm, you need to clarify what you mean by "logical host". yahoo.com resolves to (for me right at this minute) 66.94.234.13, whereas shopping.yahoo.com is a CNAME to pdb3.shop.yahoo.akadns.net which is yet another IP. Perhaps if you can expand on what your definition of "logical host" is you can get a decent answer.

Re: Extract Host, Logical Host from URL
by andreas1234567 (Vicar) on Aug 15, 2007 at 05:35 UTC
    You mean something like this?
    use strict; use warnings; print m/^.*?(\w+\.\w+)$/ while(<DATA>); __DATA__ shopping.yahoo.com yahoo.com some.very.long.url.at.yahoo.com
    $ perl -l 632539.pl yahoo.com yahoo.com yahoo.com
    --
    Andreas
Re: Extract Host, Logical Host from URL
by strat (Canon) on Aug 15, 2007 at 05:48 UTC

    see URI for parsing URIs. If you just want to get the "main" domain, you could try something like  join(".", ( split(/\./, $domains ) )[-2,-1] ) (if I understand you correctly)

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://632539]
Approved by grep
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2014-12-25 09:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (159 votes), past polls