我试图从印度电影印地语评论页面的时间检索平均用户评分,但我无法这样做,它只是一无所获。我在想,原因是因为它是动态加载的。
这是我写的代码:
library('rvest')
avg_readerrating<-c()
v2<-"http://timesofindia.indiatimes.com/entertainment/hindi/movie-
reviews/moviearticlelistdatewise1/2742919.cms?query=*:*&startdate=2015-01-
01&enddate=2015-01-31§ionid=2742919"
url<-gsub("monthR",month[i],gsub("dateR",date[i],v2))
download.file(url, destfile = 'H:/whatever.html')
web <- read_html('H:/whatever.html')
avg_readerrating_html<-html_nodes(web,xpath='//*
[@id="articlenew"]/div/div[2]/div[2]/div/span[2]')
avg_readerrating_Tab<-html_text(avg_readerrating_html)
avg_readerrating<-c(avg_readerrating,avg_readerrating_Tab)
运行此代码后,它只在输出中显示""
。请回答我如何从网站上删除动态数据。
答案 0 :(得分:0)
如果您要从网站解析html表格,请尝试XML
包裹:
library(XML)
library(RCurl)
library(rlist)
v2<-"http://timesofindia.indiatimes.com/entertainment/hindi/movie-reviews/moviearticlelistdatewise1/2742919.cms?query=*:*&startdate=2015-01-01&enddate=2015-01-31§ionid=2742919"
theurl <- getURL(v2,.opts = list(ssl.verifypeer = FALSE) )
tables <- readHTMLTable(theurl)
tables <- list.clean(tables, fun = is.null, recursive = FALSE)
这样您就可以从网站上获取用户评级表。此外,您可以关注this以获取其他替代方案。