-1
如何知道网站是否使用robot.txt和sitemap.txt?我已经完成提取关键字,描述,标题;但我无法找到代码的方式来检查网站是否使用robot.txt和sitemap.txt。检查网站是否使用站点地图和机器人文件
我做这样的http://www.seoptimer.com/report/loadster.in/5553240531d12
如何知道网站是否使用robot.txt和sitemap.txt?我已经完成提取关键字,描述,标题;但我无法找到代码的方式来检查网站是否使用robot.txt和sitemap.txt。检查网站是否使用站点地图和机器人文件
我做这样的http://www.seoptimer.com/report/loadster.in/5553240531d12
使用的file_get_contents东西:
$robotsContents = file_get_contents("http://targetdomain.com/robots.txt");
$sitemapContents = file_get_contents("http://targetdomain.com/sitemap.xml");
检查的内容是假的,假的就意味着404没找到,然后检查,如果它不是HTML内容(因为有些站点重定向每个URL)与strpos($robotsContents, '<html') === false
,如果没有标签,则表示它可以是txt或xml文件。
所以:
function pathExistsAndIsNotHtml($path) {
$contents = @file_get_contents($path);
return ! empty($contents) && strpos($contents, '<html') === false;
}
if(pathExistsAndIsNotHtml("http://targetdomain.com/robots.txt")) {
echo '<a href="http://targetdomain.com/robots.txt">http://targetdomain.com/robots.txt</a>';
} else {
echo 'There is no robots.txt';
}
if(pathExistsAndIsNotHtml("http://targetdomain.com/sitemap.xml")) {
echo '<a href="http://targetdomain.com/sitemap.xml">http://targetdomain.com/sitemap.xml</a>';
} else {
echo 'There is no sitemap.xml';
}
谢谢你,它的工作,在这里我不想显示我只是想阅读的内容,内容并显示http://targetdomain.com/robots.txt链接。怎么做? – user1992
谢谢..现在我想下载它的pdf格式 – user1992
这不是Stackoverflow的目的,你不会在这里得到你的完整代码。我们在帖子上回答了一个有问题的问题。如果安装是正确的,请验证它,并在另一篇文章中给出您的代码以及阻止您的代码。 – KyleK