我正在学习rvest
0.3.1包。
使用 this tutorial 中的代码,我只将html
更改为read_html
library(rvest)
# Store web url
lego_movie <- read_html("http://www.imdb.com/title/tt1490017/")
#Scrape the website for the movie rating
rating <- lego_movie %>%
html_nodes("strong span") %>%
html_text() %>%
as.numeric()
rating
# Scrape the website for the cast
cast <- lego_movie %>%
html_nodes("#titleCast .itemprop span") %>%
html_text()
cast
然而,评级和演员只是返回
numeric(0)
character(0)
如何解决这个问题的任何建议都会受到赞赏吗?
更新
我在rvest v0.3.1
上使用xml2 v0.1.2
和R 3.2.3
,但仍在评分和投票回报
numeric(0)
character(0)
下面是逐步运行代码
rating <- lego_movie
rating
{xml_document}
<html>
[1] <head>\n <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>\n <title>\n Web Filter Block Override\n </title>\n <style type="text/css"><![CDAT ...
[2] <body class="authenticate">\n <div class="header">\n <h2>\n Powered By Fortinet\n </h2>\n <h1>\n FortiGuard Web Filtering\n </h1>\n </di ...
rating <- lego_movie %>%
html_nodes("strong span")
rating
{xml_nodeset (0)}
rating <- lego_movie %>%
html_nodes("strong span") %>%
html_text()
rating
character(0)
rating <- lego_movie %>%
html_nodes("strong span") %>%
html_text() %>%
as.numeric()
rating
numeric(0)