找不到web爬网程序php的变量



我正在php中开发一个网络爬虫,我总是遇到这个问题,但我没有找到解决它的方法

注意:未定义的变量:第16行上C:\examplep\htdocs\dousser\index.php中的website_to_crawl

这是我的第二篇文章,没有显示错误,但也没有显示

<?php 
$website_to_crawl= "http://php.net";
$all_links= array();

function get_links($url)
{
global $all_links;
$contents= @file_get_contents($url);
$regexp= "<as[^>]*href=("??)([^" >]*?)\1[^>]*>(.*)</a>";
preg_match_all("/$regexp/siU", $contents, $matches);
$path_of_url= parse_url($url, PHP_URL_HOST);
if (strpos($url, "https://") == true)
{
$type= "https://";
}
else
{
$type= "http://";
}

$links_in_array= $matches[2];
foreach ($links_in_array as $link)
{
if (strpos($link, "#") !== false)
{
$link= substr($link,0, strpos($link, "#"));
}
if (substr($link, 0, 1) == ".")
{
$link= substr($link,1);
}
if (substr($link, 0, 7) == "http://") {
$link= $link;
}
else if (substr($link, 0, 8) == "https://") {
$link= $link;
}
else if (substr($link, 0, 2) == "//") {
$link= substr($link,2);
}

else if (substr($link, 0, 1) == "#") {
$link= $url;
}
else if (substr($link, 0, 7) == "mailto:") {
$link= "[" . $link . "]";
}
else if (substr($link, 0, 1) != "/") {
$link= "$type" .$path_of_url. "/" . $link;
}
else 
{
$link= "$type" .$path_of_url.$link;
}

if (!in_array($link,$all_links))
{
array_push($all_links, $link);
}

}//ends foreach 
}//ends function get_links
get_links($website_to_crawl);
foreach ($all_links as $currentlink)
{
get_links($currentlink);
}
foreach ($all_links as $currentlink)
{
get_links($currentlink);
}
foreach ($all_links as $currentlink)
{
if ((strpos($currentlink, "www.php.net") !== FALSE) && (strpos($currentlink, "http", 4) == FALSE))
{
echo $currentlink . "<br>";
$linkscount[] += $currentlink;
}
}
$count= count($linkscount);
echo "<br><br>There are $count links found by the crawler";
?>

此变量用于$website_to_crawl网站进行爬网我已经查过是http网站还是https网站我已经测试了

提前感谢在这种情况下,我正在使用网站url 进行网络爬虫

您可以使用:

if (strpos($url, "https://") == true)

而不是

if (strpos($website_to_crawl, "https://") == true)

最新更新