首页 > 解决方案 > 我试图弄清楚是否允许 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

谢谢。

标签: rweb-scraping

解决方案


只需使用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/

推荐阅读