我正在尝试确定是否允许GoogleNews进行Webscrap

时间:2019-09-25 18:04:46

标签: r web-scraping

我正在使用 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

谢谢。

1 个答案:

答案 0 :(得分:0)

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