大网数据广告活动
网站运营与故障问答

What is the way to prevent Google from scraping and crawling a URL in plain text on a page?

· 52CE 我爱测

Problem I have a website with documentation that includes examples with plain text URLs. The other day, I noticed that Google Webmaster was telling me that one of those URLs generated a Page Not Found error. Question What is the …

问题原文

原帖链接 · Alexis Wilke · CC BY-SA 3.0

Problem

I have a website with documentation that includes examples with plain text URLs. The other day, I noticed that Google Webmaster was telling me that one of those URLs generated a Page Not Found error.

Question

What is the best way to prevent Google from scraping such plain text URLs? (other than using example.com because I am using my domain name in those sample URLs, which I think makes more sense.)

Hide directory solution

Note that I found out that I could add a folder, in my case /api, to the robots.txt and at least all of those URLs were ignored.

User-agent: *
Disallow: /api

However, all the URLs in my documentations are not just about the REST API and I still have the problem with some other pages that I just cannot add to robots.txt (at least, to me that would not make sense, adding each page individually to robots.txt, when those pages do not exist in the first place?!)

That being said, I'm not so sure that this is a good solution as far as SEO is concerned since in effect those pages still generate an Internal Link 404 error (or maybe it's considered to be a 403?).

已采纳解答

原帖链接 · ddyer · CC BY-SA 3.0

Generate the text with a simple javascript function, so the literal you want will appear when read, but not when scraped.

in the header something like

<script>function hide(str)
{   
    document.write('http://example.com'+str);
}
</script>

In line something like

<script>hide("/foo/bar.html")</script>

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Webmasters Stack Exchange
适用范围
以原帖系统、软件版本与发布日期为准(2017-09-03)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 3.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。