简体   繁体   English

R中的jsonlite包错误

[英]Error with jsonlite package in R

Has anyone ever received this error when trying to web scrape a site: 尝试通过网络抓取网站时,是否有人收到此错误消息:

Error in feed_push_parser(readBin(con, raw(), n), reset = TRUE) :
lexical error: invalid char in json text.
                                     <!doctype html><html xmlns="htt
                   (right here) ------^

I do not understand why I am receiving this error when I scraped the first page of the site no problem with the same declaration on that first page. 我不明白为什么我在抓取网站的第一页时没有问题,并且在第一页上使用相同的声明时仍收到此错误。 But the second page I get this error. 但是第二页我得到这个错误。 Is there a way around this? 有没有解决的办法?

This works fine: 这工作正常:

    jsonlite::fromJSON("https://www.reddit.com/r/BestOfStreamingVideo/.json", flatten = TRUE)

Get the error here: 在此获取错误:

jsonlite::fromJSON("https://www.reddit.com/r/BestOfStreamingVideo/?count=25&after=t3_5fvgls/.json", flatten = TRUE)

The latter one does not return a JSON. 后者不返回JSON。 It returns HTML. 它返回HTML。 Enter both URL's in the browser and you'll see the difference. 在浏览器中输入两个URL,您将看到区别。

I guess the URL you are looking for is: 我猜您正在寻找的URL是:

https://www.reddit.com/r/BestOfStreamingVideo/.json?count=25&after=t3_5fvgls/ https://www.reddit.com/r/BestOfStreamingVideo/.json?count=25&after=t3_5fvgls/

You need to put the ./json first and append the URL parameter after. 您需要先放置./json并在./json附加URL参数。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM