topical media & game development
alt-bot-lib-simple-spider.php / php
<?php
/*
#################################################################
Copyright 2007, Michael Schrenk
This software is designed for use with the book,
"Webbots, Spiders, and Screen Scarpers", Michael Schrenk, 2007 No Starch Press, San Francisco CA
W3CŪ SOFTWARE NOTICE AND LICENSE
This work (and included software, documentation such as READMEs, or other
related items) is being provided by the copyright holders under the following license.
By obtaining, using and/or copying this work, you (the licensee) agree that you have read,
understood, and will comply with the following terms and conditions.
Permission to copy, modify, and distribute this software and its documentation, with or
without modification, for any purpose and without fee or royalty is hereby granted, provided
that you include the following on ALL copies of the software and documentation or portions thereof,
including modifications:
1. The full text of this NOTICE in a location viewable to users of the redistributed
or derivative work.
2. Any pre-existing intellectual property disclaimers, notices, or terms and conditions.
If none exist, the W3C Software Short Notice should be included (hypertext is preferred,
text is permitted) within the body of any redistributed or derivative code.
3. Notice of any changes or modifications to the files, including the date changes were made.
(We recommend you provide URIs to the location from which the code is derived.)
THIS SOFTWARE AND DOCUMENTATION IS PROVIDED "AS IS," AND COPYRIGHT HOLDERS MAKE NO REPRESENTATIONS OR
WARRANTIES, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO, WARRANTIES OF MERCHANTABILITY OR FITNESS
FOR ANY PARTICULAR PURPOSE OR THAT THE USE OF THE SOFTWARE OR DOCUMENTATION WILL NOT INFRINGE ANY THIRD
PARTY PATENTS, COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS.
COPYRIGHT HOLDERS WILL NOT BE LIABLE FOR ANY DIRECT, INDIRECT, SPECIAL OR CONSEQUENTIAL DAMAGES ARISING OUT
OF ANY USE OF THE SOFTWARE OR DOCUMENTATION.
The name and trademarks of copyright holders may NOT be used in advertising or publicity pertaining to the
software without specific, written prior permission. Title to copyright in this software and any associated
documentation will at all times remain with copyright holders.
#################################################################
*/
*********************************************************************
harvest_links(url
Fully resolved web address of target web page
RETURNS:
Returns an array of links
*********************************************************************
function harvest_links(DELAY;
url
url);
# Download webpage
sleep(downloaded_page = http_get(anchor_tags = parse_array(xx=0; anchor_tags); href = get_attribute(xx], "href");
href, link_array[] = resolved_addres." \n";
}
return
*********************************************************************
archive_links(spider_array, temp_link_array)
-------------------------------------------------------------
DESCRIPTION:
Puts raw links into an archival array
INPUT:
penetration_level
Page depth at which the spidering was conducted
temporary array of raw links
RETURNS:
Returns archival array
*********************************************************************
function archive_links(penetration_level, xx=0; temp_link_array); spider_array
if(!excluded_link(temp_link_array[spider_array[temp_link_array[spider_array;
}
*********************************************************************
get_domain(url
The web address
RETURNS:
Returns the domain for the inputed url
*********************************************************************
function get_domain(url
url);
url);
// Remove page and directory references
if(stristr(url = substr(url, "/"));
return
*********************************************************************
excluded_link(spider_array, spider_array
The spider's archival array
function excluded_link(spider_array, SEED_URL, ALLOW_OFFISTE;
link, "javascript"))
{
echo "Ignored JavaScript fuction: exclude=true;
}
// Exclude redundant links
for(xx<count(xx++)
{
saved_link))
{
spider_array[link == array_pop(xx]))
{
echo "Ignored redundant link: exclude=true;
break;
}
}
}
// Exclude links found in xx=0; exclusion_array); link, xx]))
{
echo "Ignored excluded link: exclude=true;
}
}
// Exclude offsite links if requested
if(link)!=get_domain(link\n";
exclude;
}
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.