r - 我试图弄清楚是否允许 GoogleNews 进行网络抓取
问题描述
我正在使用包robotstxt中的paths_allowed函数 来确定是否可以从特定网站上抓取数据,在我的例子中是https://news.google.com/?hl=en-IN&gl=IN&ceid=IN%3Aen,但是每次我这样做我都会出错
library(robotstxt)
paths_allowed(paths = "https://news.google.com/?hl=en-IN&gl=IN&ceid=IN%3Aen")
错误信息是这样的:
news.google.com Error in if (is_http) { : argument is of length zero
谢谢。
解决方案
只需使用httr
包并发布GET
请求以https://news.google.com/robots.txt
获取我们需要的信息:
a <- httr::GET("https://news.google.com/robots.txt")
httr::content(a)
User-agent: *
Disallow: /
Disallow: /search?
Allow: /$
Allow: /?
Allow: /nwshp$
Allow: /news$
Allow: /news/$
Allow: /news/?gl=
Allow: /news/?hl=
Allow: /news/?ned=
Allow: /about$
Allow: /about?
Allow: /about/
Allow: /topics/
Allow: /publications/
Allow: /stories/
Allow: /swg/
User-agent: Googlebot
Disallow: /topics/
Disallow: /publications/
Disallow: /stories/
推荐阅读
- docker - Helm 中 Kubernetes 上的 Jenkins - 如何将 ssh 密钥附加到代理
- javascript - Javascript动画未显示
- vuejs2 - VueJS - 当我使用 $emit 时自定义事件不起作用
- javascript - 是否可以在 Node 模块中导出动态导入?
- bash - 打开一个新的 git-bash 终端并在其中运行命令
- security - 如何在 Contiki / Cooja 模拟器中启用 LLSEC?
- node.js - 来自 tsconfig.json 的路径在 tsc 之后不起作用
- powerbi - DirectQuery PowerBI 中的 DAX 公式兼容性 - 匹配来自另一个表的值
- excel - VBA,IF逻辑错误,如何退出
- typedoc - 如何自定义 TypeDoc 主题?