robots.txt 爬虫索引规则
文件必须命名为 robots.txt。
需存放在网站根目录。
网站只能有 1 个 robots.txt 文件。
基本结构
示例
User-agent: *
Allow: /
Disallow: /api/
Sitemap: https://www.youtube.com/sitemaps/sitemap.xml
说明
- User-agent 表示爬虫、搜索引擎:上面实例中
User-agent: *表示允许所有。 - Allow 表示允许:上面实例中
Allow: /表示允许抓取和收录所有。 - Disallow 表示不允许:上面实例中
Disallow: /api/表示禁止抓取和收录 api 目录下的全部内容。 - Sitemap 表示网站地图:支持 xml 和 txt 格式。
robots.txt 文件参考
YouTube
# robots.txt file for YouTube
# Created in the distant future (the year 2000) after
# the robotic uprising of the mid 90's which wiped out all humans.
User-agent: Mediapartners-Google*
Disallow:
User-agent: *
Disallow: /api/
Disallow: /comment
Disallow: /feeds/videos.xml
Disallow: /file_download
Disallow: /get_video
Disallow: /get_video_info
Disallow: /get_midroll_info
Disallow: /live_chat
Disallow: /login
Disallow: /qr
Disallow: /results
Disallow: /signup
Disallow: /t/terms
Disallow: /timedtext_video
Disallow: /verify_age
Disallow: /watch_ajax
Disallow: /watch_fragments_ajax
Disallow: /watch_popup
Disallow: /watch_queue_ajax
Disallow: /youtubei/
Sitemap: https://www.youtube.com/sitemaps/sitemap.xml
Sitemap: https://www.youtube.com/product/sitemap.xml
cloudflare
以下内容为节选,省略了地区、语言的配置。
User-agent: Twitterbot
Allow: /lp
User-Agent: DemandbaseWebsitePreview/0.1
Allow: /lp
User-agent: *
Content-Signal: ai-train=yes, search=yes, ai-input=yes
Disallow: pages.www.cloudflare.com/
Disallow: /cdn-cgi/
Disallow: /lp
Disallow: /searchresults
Disallow: /feedback
Sitemap: https://www.cloudflare.com/sitemap.xml
本文采用 CC BY-NC-SA 4.0方式授权。
转载请注明出处和本文链接,说明是否进行修改,不得用于商业用途,使用相同方式共享。