免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2044 | 回复: 0
打印 上一主题 下一主题

求助网页抓取代码 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-03-23 18:19 |只看该作者 |倒序浏览
小弟有一段代码看不明 ,望大虾们指点 谢谢
代码如下:
<?
class SpiderConfig
{
        var $saveRootDirectory = ".";
        var $mailtoLogFile = "mailto.txt";
       
        var $refreshHTMLs = true;
        var $refreshImages = false;
        var $refreshOthers = false;
       
        var $htmlExtensions = array("htm","html","shtml","php","asp","jsp","net","aspx") ;
        var $imageExtensions = array("jpg","gif","png");
       
        var $startLocation;
        var $urlMatch = "";
       
        var $interestingURLSubstrings = array();
        var $boringURLSubstings = array();
       
        var $depthFirst = false;
        var $maxDepth = 0;
       
        var $userAgent = "Weblech Spider ";
       
        var $basicAuthUser = "";
        var $basicAuthUserPassworc = "";
       
        var $checkPointInterval = 0;

function SpiderConfig($props)
        {
                $this->saveRootDirectory = $props->getItem("saveRootDirectory");
                if(!is_dir($this->saveRootDirectory))
                {
                        if(!mkdir($this->saveRootDirectory))
                        {
                                echo "<br>Couldn't create root directory:"+$this->saveRootDirectory;
                                $this->saveRootDirectory = ".";
                        }
                }
                $mailtoFileStr = $props->getItem("mailtoLogFile");
               
                if(strstr($mailtoFileStr,":")!=false||substr($mailtoFileStr,0,1)=="/"||substr($mailtoFileStr,0,1)=="\\")
                {
                        echo "<br>Using absolute file name ".$mailtoFileStr;
                        $fp = fopen($mailtoFileStr,"w");
                        fclose($fp);
                }
                else
                {
                        echo "<br>Construction relative file name ".$this->saveRootDirectory."/".$mailtoFileStr;
                        $fp = fopen($this->saveRootDirectory."/".$mailtoFileStr,"w");
                        fclose($fp);
                }
                $this->refreshHTMLs = ($props->getItem("refreshHTMLs"));
                $this->refreshImages = ($props->getItem("refreshImages"));
                $this->refreshOthers = ($props->getItem("refreshOthers"));
               
                $this->htmExtensions = $this->parseSet($props->getItem("htmlExtensions"));
                $this->imageExtensions = $this->parseSet($props->getItem("imageExtensions"));
               
                $startLocStr = $props->getItem("startLocation");
                if($startLocStr)
                {
                        $this->startLocation = $startLocStr;
                }
                else
                {
                        echo "<br>startLocation not found in properities";
                }
                $this->urlMatch = $props->getItem("urlMatch");
               
                $this->interestingURLSubstrings = $this->parsePropCommaSepareted($props->getItem("interestingURLs"));
                $this->boringURLSubstrings = $this->parsePropCommaSepareted($props->getItem("boringURLs"));
               
                $this->depthFirst = $props->getItem("depthFirst");
                $this->maxDepth = $props->getItem("maxDepth");
               
                $this->userAgent = $props->getItem("userAgent");
                $this->basicAuthUser = $props->getItem("basicAuthUser");
                $this->basicAuthPassword = $props->getItem("basicAuthPassword");
               
                $this->checkpointInterval = $props->getItem("checkpointInterval");
        }
function parsePropCommaSepareted($str)
        {
                $result = array();
                if($str!=""&&strlen($str))
                {
                        $result = explode(",",$str);
                }
                return $result;
        }

function setRefreshHTMLs($refreshHTMLs)
        {
                $this->refreshHTMLs= $refreshHTMLs;
        }
function refreshHTMLs()
        {
                return $this->refreshHTMLs;
        }
function setRefreshImages($refreshImages)
        {
                $this->refreshImages = $refreshImages;
        }
function refreshImages()
        {
                return $this->refreshImages;
        }
function setRefreshOthers($refreshOthers)
        {
                $this->refreshOthers = $refreshOthers;
        }
function refreshOthers()
        {
                return $this->refreshOthers;
        }
function setSaveRootDirectory($saveRootDirectory)
        {
                $this->saveRootDirectory = $saveRootDirectory;
        }
function getSaveRootDirectory()
        {
                return $this->saveRootDirectory;
        }
function setMailtoLogFile($mailtoLogFile)
        {
                $this->mailtoLogFile = $mailtoLogFile;
        }
function getMailtoLogFile()
        {
                return $this->mailtoLogFile;
        }
function setStartLocation($startLocation)
        {
                $this->startLocation = $startLocation;
        }
function getStartLocation()
        {
                return $this->startLocation;
        }
       
function setURLMatch($urlMatch)
        {
                $this->urlMatch = $urlMatch;
        }
function getURLMatch()
        {
                return $this->urlMatch;
        }
function getInterestingURLSubstrings()
        {
                return $this->interestingURLSubstrings;
        }
function setInterestingURLSubstings($interestingURLSubstrings)
        {
                $this->interestingURLSubstrings = $interestingURLSubstrings;
        }
function getBoringURLSubstrings()
        {
                return $this->boringURLSubstrings;
        }
function setBoringURLSubstings($boringURLSubstrings)
        {
                $this->boringURLSubstrings = $boringURLSubstrings;
        }
function isInteresting($u)
        {
                return $this->matchURL($u,$this->interestingURLSubstrings);
        }
function isBoring($u)
        {
                return $this->matchURL($u,$this->boringURLSubstrings);
        }
function matchURL($u,$substrings)
        {
                $url = $u->getURL();
                foreach($substrings as $value)
                {
                        if(strstr($url,$value)!=false)
                        {
                                return true;
                        }
                }
                return false;
        }
function setDepthFirstSearch($depthFirst)
        {
                $this->depthFirst = $depthFirst;
        }
function isDepthFirstSearch()
        {
                return $this->depthFirst;
        }
function setMaxDepth($maxDepth)
        {
                $this->maxDepth = $maxDepth;
        }
function getMaxDepth()
        {
                return $this->maxDepth;
        }
function setUserAgent($userAgent)
        {
                $this->userAgent = $userAgent;
        }
function getUserAgent()
        {
                return $this->userAgent;
        }
function setBasicAuthUser($basicAuthUser)
        {
                $this->basicAuthUser = $basicAuthUser;
        }
function getBasicAuthUser()
        {
                return $this->basicAuthUser;
        }
function setBasicAuthPassword($basicAuthPassword)
        {
                $this->basicAuthPassword = $basicAuthPassword;
        }
function getBasicAuthPassword()
        {
                return $this->basicAuthPassword;
        }
function setCheckpointInterval($checkpointInterval)
        {
                $this->checkpointInterval = $checkpointInterval;
        }
function getCheckpointInterval()
        {
                return $this->checkpointInterval;
        }
function toString()
        {
                return ;
        }
function parseSet($str)
        {
                echo "<br>parseSet(".$str.")";
                $result =explode($str,",");
                return $result;
        }
function fromSet($s)
        {
                if(is_array($s))
                {
                        return implode(",",$s);
                }
                return "";
        }
}
?>
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP