robots.txt 和 sitemap

robots.txt 和 sitemap,第1张

概述为了爬虫, 在网站根目录创建robots.txt文件(utf-8),文件内容涉及四类键值对:User-agent,Disallow,Allow,Sitemap,支持正则, Disallow后没内容就是

为了爬虫,在网站根目录创建robots.txt文件(utf-8),文件内容涉及四类键值对:User-agent,disallow,Allow,Sitemap,支持正则,disallow后没内容就是允许所有

User-agent: *disallow:disallow: /cgi-bin/disallow: /admin/Sitemap: https://zdb.im/sitemap.xml

sitemap四种写法:

 

第一种,文本格式,sitemap.txt,一行一个URL地址
https://zdb.im/https://zdb.improject.HTML

第二种, HTML格式,允许加style标签,一般布局是 HTML>body>ul>li>a[href,Title]>plainText,URL用全路径,爬虫递归往下找;

 

第三种,单个XML文件,默认文件名sitemap.xml,百度是sitemap_baIDu.xml

权重: 0.0到1.0,

设备: 代码适配<mobile:mobile type="HTMLadapt"/>,自适应设备<mobile:mobile type="pc,mobile"/>,移动端<mobile:mobile type="mobile"/>,默认不填是PC端;

刷新频率: always 经常,hourly 每小时,daily 每天,weekly 每周,monthly 每月,yearly 每年,never 从不

修改时间: 2019-11-28或2019-11-28T11:59:38+00:00 皆可,建议第二种;

年:YYYY(2005)

年和月:YYYY-MM(2005-06)

年月日:YYYY-MM-DD(2005-06-04)

年月日小时分钟:YYYY-MM-DDThh:mmTZD(2005-06-04T10:37+08:00)

年月日小时分钟秒:YYYY-MM-DDThh:mmTZD(2005-06-04T10:37:30+08:00)

<?xml version="1.0" enCoding="UTF-8"?><urlset    xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"    xsi:schemaLocation="http://www.sitemaps.org/schemas/sitemap/0.9"><url> <loc>https://zdb.im/</loc>     <mobile:mobile type="HTMLadapt"/> <priority>0.5</priority> <lastmod>2019-11-28T11:59:38+00:00</lastmod> <changefreq>hourly</changefreq></url><url> <loc>https://zdb.im/project.HTML</loc> <priority>0.5</priority> <lastmod>2019-11-28</lastmod> <changefreq>hourly</changefreq></url></urlset>

广州包装设计公司http://www.maiqicn.com 电脑刺绣绣花厂 ttp://www.szhdn.com

第四种,当第三种的url个数超过5万个或未压缩时大小超过10MB(10,485,760字节),建立索引文件(sitemap index),指向不超过1,000个Sitemap的URL; 索引文件的默认文件名 sitemap_index.xml;

路径必填 loc; 修改时间选填 lastmod 2009-12-14;

<?xml version="1.0" enCoding="UTF-8"?><sitemAPIndex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <sitemap>  <loc>https://zdb.im/sitemap.xml</loc> </sitemap></sitemAPIndex>

百度支持自动推送: 页面Js推送,RPC通知,URL POST

(function(){    var bp = document.createElement('script');    var curProtocol = window.location.protocol.split(':')[0];    if (curProtocol === 'https'){   bp.src = 'https://zz.bdstatic.com/linksubmit/push.Js';  }  else{  bp.src = 'http://push.zhanzhang.baIDu.com/push.Js';  }    var s = document.getElementsByTagname("script")[0];    s.parentNode.insertBefore(bp,s);})();

百度资源搜索平台,添加站点,得到token,用http主动推送;

1)curl推送示例将要提交的url数据写入一个本地文件,比如urls.txt,每个url占一行,然后调用curl命令:curl -H 'Content-Type:text/plain' --data-binary @urls.txt"http://data.zz.baIDu.com/urls?site=www.example.com&token=edk7yc4rEZP9pDQD"使用PHP、python、java等可以参照这个过程推送结构化数据。2)post推送示例POST /urls?site=www.58.com&token=edk7ychrEZP9pDQD http/1.1User-Agent: curl/7.12.1 Host: data.zz.baIDu.com Content-Length: 83http://www.example.com/1.HTMLhttp://www.example.com/2.HTML3)PHP推送示例$urls = array(    'http://www.example.com/1.HTML','http://www.example.com/2.HTML',);$API = 'http://data.zz.baIDu.com/urlssite=www.58.com&token=edk7ychrEZP9pDQD';$ch = curl_init();$options =  array(    CURLOPT_URL => $API,CURLOPT_POST => true,CURLOPT_RETURNTRANSFER => true,CURLOPT_POSTFIELDS => implode("\n",$urls),CURLOPT_httpheader => array('Content-Type: text/plain'),);curl_setopt_array($ch,$options);$result = curl_exec($ch);echo $result;

 

  总结

以上是内存溢出为你收集整理的robots.txt 和 sitemap全部内容,希望文章能够帮你解决robots.txt 和 sitemap所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1028085.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-23
下一篇2022-05-23

发表评论

登录后才能评论

评论列表(0条)

    保存