Marketing Forums                      

Welcome to the fastest-growing internet 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 Thread Tools Search this Thread Display Modes
Unread 08-10-2009, 02:49 PM   #1
dave
Extravaganzeer
 
dave's Avatar
 
Join Date: Oct 2008
iTrader: 0
Referrals: 4
Posts: 525
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 offline   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

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
What computer script goes good along with html? EliteTrader HTML & Website Design 13 12-18-2012 06:55 AM
Need Help With Butterfly Script Integrating With Aweber! ray48021 Programming Corner 0 05-20-2011 02:29 PM
Free SEO Tools: Grab now!! sweetashlee SEO - Search Engine Optimization 1 06-13-2010 12: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 11:39 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 - 2018, Jelsoft Enterprises Ltd.
Marketing Forums | This is a Metabin Ltd. Website