Marketing Forums                      

Go Back   Marketing Forums > Webmaster's Lounge > Programming Corner

Programming Corner Anything related to programming... PHP, PERL, ASP, ColdFusion, C++, etc.

Reply
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
Unread 08-10-2009, 03:49 PM   #1
Extravaganzeer
 
dave's Avatar
 
Join Date: Oct 2008
iTrader: 0
Referrals: 3
Posts: 484
Reputation: 30
dave is on a distinguished road
Post Quick php script to grab / scrape all the links from a web page

Heres a quick script to grab all the links from a website (theregister.co.uk in this case!)

Code:
<?
# retrieve the contents of the webpage in your browser
$webpagehtml=file_get_contents("http://www.theregister.co.uk");

# Then you can parse the html into a dom object
$dom=new DOMDocument();
$dom->loadHTML($webpagehtml);

$xpath=new DOMXPath($dom);
$items = $xpath->query("//a");

$links=array();

for ($i = 0;  $i < $items->length; $i++ ) {
    $item = $items->item($i);
    $title=$item->textContent;
    $href=$item->getAttribute('href');
    
    if($href && $title){
        echo "$href = $title<br/>";
    }
}
Any requests?

Please read the Rules
dave is online now  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiTweet this Post!
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
What computer script goes good along with html? EliteTrader HTML & Website Design 7 12-06-2011 11:13 AM
I have a new website, how can I need quick access to external links promdresses72 Blogging Forums 0 07-04-2011 06:12 AM
Need Help With Butterfly Script Integrating With Aweber! ray48021 Programming Corner 0 05-20-2011 03:29 PM
Free SEO Tools: Grab now!! sweetashlee SEO - Search Engine Optimization 1 06-13-2010 01:38 PM
WTB : PPC SE using ProSearch Script BossLady Websites For Sale or Wanted 0 11-11-2008 10:42 PM


All times are GMT. The time now is 01:14 PM.


Navigation
Marketing Forums Homepage
Forum Home
Marketing Forums News
iTrader
Calendar
Forum Rules
Forum Statistics

FREE Link Directory
Link Directory Home
Link Exchange Programs
Affiliate Networks
Business Opps
CPM Ad Networks
Contextual Ad Networks
Domain Parking
Paid To Click
Paid To Read
Paid For Action
Paid To Promote
Shopping Rewards
Pay Per Click Programs
PPC Search Engines
Pay Per Sale
Work At Home Opps
Advertisements

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.5.2
Marketing Forums | This is a Metabin Ltd. Website