【发布时间】:2016-03-14 06:27:18
【问题描述】:
我正在学习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)
如有任何解决此问题的建议,我们将不胜感激?
更新
我在R 3.2.3 上使用rvest v0.3.1 和xml2 v0.1.2,但仍然评分和演员回报
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)
【问题讨论】:
-
你的代码对我有用
-
@Symbolix 感谢您花时间尝试。为什么你认为它不适合我?
-
是否正确安装了
xml2? -
@Symbolix 我将它安装为其他包 install.packages("xml2")。有具体的安装方式吗?
-
我不知道,我只是猜测它可能是个问题。