NamePros
Welcome, Guest! Ready to make a name for yourself in the domain business? We welcome both the hobbyist and professional domainer to join the discussion as part of the NamePros community.

Click here to create your profile to start earning reputation for posting, and trader ratings for buying & selling in our free e-marketplace. Build your trader rating with each successful sale. Our system has tracked over 100,000 sales and counting!
FAQ & TOS Register Search Today's Posts Mark Forums Read

Go Back   NamePros.com > Website Development Discussion Forums > Programming > CODE
Reload this Page Get all links from a page

CODE This forum is for posting code snippets and example scripts that aren't quite tutorials, but could be useful for others. You may post code snippets and/or completed scripts that you've written and want to share here.

Advanced Search


Closed Thread
 
LinkBack Thread Tools
Old 07-29-2007, 01:17 PM THREAD STARTER               #1 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




Get all links from a page


This code will get all links from a page, example. I developed it as part of a simple spider i'm working on.

This is what i'm using it for, obviously it's not finished, but I think its a pretty good (if strange) idea. Needs JavaScript. Only tested in Opera.

PHP Code:
<pre><?php

$url 
$_GET['url'];
$html file_get_contents($url);
$preg = array();
$base = array();
$links = array();
$parsed parse_url($url);

preg_match_all("/\<a(\s*)href(\s*)=(\s*)\"(.*?)\"(.*?)\>(.*?)\<\/a\>/i"$html$preg[0]);
preg_match_all("/\<a(\s*)href(\s*)=(\s*)'(.*?)'(.*?)\>(.*?)\<\/a\>/i"$html$preg[1]);
preg_match("/\<base(\s*)href(\s*)=(\s*)\"(.*?)\"(\s*)\/\>/i"$html$base);

$title array_merge($preg[0][6], $preg[1][6]);
$href array_merge($preg[0][4], $preg[1][4]);
????: NamePros.com http://www.namepros.com/code/355541-get-all-links-from-a-page.html
$base $base[4];

if(empty(
$base))
    
$base = (!empty($parsed['user'])) ? "{$parsed['scheme']}://{$parsed['user']}:{$parsed['pass']}@{$parsed['host']}"{$parsed['scheme']}://{$parsed['host']}";

for(
$i 0$i count($href); $i ++){
    if(
substr($href[$i], 01) == '/')
        
$href[$i] = "{$base}{$href[$i]}";
    if(
substr($href[$i], 01) == '?' || substr($href[$i], 01) == '#')
        
$href[$i] = "{$url}{$href[$i]}";
????: NamePros.com http://www.namepros.com/showthread.php?t=355541
    
$links[$i] = array("title" => htmlentities($title[$i]), "url" => htmlentities($href[$i]));
}

print_r($links);

?></pre>
Last edited by Mikor; 07-29-2007 at 03:23 PM.
Barrucadu is offline  
Old 08-04-2007, 11:13 AM   #2 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
 


Ethan Allen Fund Ethan Allen Fund
I like it!

Very good potential on this script, thanks for posting.

You don't suppose you could post/zip the other files, .css, .js (although I think it's inline), and .php - We could of course source them, but it's polite to ask.

Thanks,

Dan
Daniel is offline  
Old 08-05-2007, 04:45 PM   #3 (permalink)
Senior Member
 
Joseph's Avatar
Join Date: Dec 2004
Location: Ireland
Posts: 2,684
Joseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond reputeJoseph has a reputation beyond repute
 


Animal Cruelty 9/11/01 :: Never Forget Find Marrow Donors! Save The Children Save The Children Save The Children Ethan Allen Fund Baby Health Child Abuse Cancer AIDS/HIV Autism Autism Lou Gehrig's Disease (ALS) Parkinson's Disease Alzheimer's Cancer Save a Life Cancer Cancer Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009 Help The Homeless - Holiday 2009
Thanks

Repped
Joseph is offline  
Old 08-06-2007, 12:07 AM THREAD STARTER               #4 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




Here you go, make sure to set the url it will be hosted at in class.php
http://mikor.clearlyhosted.org/spider/zipped.rar
Barrucadu is offline  
Old 08-06-2007, 12:54 PM   #5 (permalink)
Danltn.com
 
Daniel's Avatar
Join Date: May 2007
Location: Danltn.com / Nottingham, UK
Posts: 1,201
Daniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond reputeDaniel has a reputation beyond repute
 


Ethan Allen Fund Ethan Allen Fund
Is this Open Source, unrestricted code? I have a commercial use of this, I can send you a finished script with Resell Rights in exchange for full reseller rights usage of the code.

Thanks,

Dan.

(P.S. Please don't say no )
Daniel is offline  
Old 08-06-2007, 03:22 PM THREAD STARTER               #6 (permalink)
Senior Member
 
Barrucadu's Avatar
Join Date: Aug 2005
Location: East Yorkshire, England
Posts: 2,689
Barrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to beholdBarrucadu is a splendid one to behold
 




Originally Posted by Danltn
Is this Open Source, unrestricted code? I have a commercial use of this, I can send you a finished script with Resell Rights in exchange for full reseller rights usage of the code.
????: NamePros.com http://www.namepros.com/showthread.php?t=355541

Thanks,

Dan.

(P.S. Please don't say no )
Of course.
Barrucadu is offline  
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools


Liquid Web Smart Servers  
All times are GMT -7. The time now is 02:08 AM.

Managed Web Hosting by Liquid Web
Domain name forum recommended by Domaining.com Powered by: vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.6.0 Ad Management plugin by RedTyger