在 R 中使用 rvest 在 IMDb 上抓取乐高电影
Scraping The Lego Movie on IMDb using rvest in R
我正在学习 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
然而,评级和投射仅 return
numeric(0)
character(0)
如有任何解决此问题的建议,我们将不胜感激?
更新
我在 R 3.2.3
上使用 rvest v0.3.1
和 xml2 v0.1.2
,但仍在评分和投射 return
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)
在 R 3.2.3
上使用 rvest v0.3.1
(和 xml2 v0.1.2
),您使用的代码应该可以工作。这是它在我的环境中工作的屏幕截图
代码只需在开头添加以下行即可运行
Sys.setenv(http_proxy="http_proxy=tur-cache2.massey.ac.nz:8080 http_proxy_user=ask")
我正在学习 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
然而,评级和投射仅 return
numeric(0)
character(0)
如有任何解决此问题的建议,我们将不胜感激?
更新
我在 R 3.2.3
上使用 rvest v0.3.1
和 xml2 v0.1.2
,但仍在评分和投射 return
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)
在 R 3.2.3
上使用 rvest v0.3.1
(和 xml2 v0.1.2
),您使用的代码应该可以工作。这是它在我的环境中工作的屏幕截图
代码只需在开头添加以下行即可运行
Sys.setenv(http_proxy="http_proxy=tur-cache2.massey.ac.nz:8080 http_proxy_user=ask")