There are several ways to get data, such as TXT, Excel, curl, database, etc., I prefer curl and database, first introduce the next Rcurl
Load Rcurl Bag
Http://cran.r-project.org/web/packages/RCurl/index.html
Two installation
?
1 |
sudo R CMD INSTALL RCurl_1.95-4.1.tgz |
three-Test run
Error, found missing another package, Bitops
Four-Mount Bitops
Http://cran.r-project.org/web/packages/bitops/index.html
Run
sudo R CMD INSTALL bitops_1. 0-6. tgz
Five Install XML packages
What can I do if I see an instance from the Internet that needs this package? Ann Bar
: http://cran.r-project.org/web/packages/XML/index.html
Command Line Input:
sudo R CMD INSTALL xml_3. 98-1.1. tgz
Silly, the name can be directly under R input the install command
Six Rjsonio Packages Installed
Installation failed with r built-in install command, continued after the old-fashioned installation, successfully
Seven example
Get the score for the frozen videos in watercress, with the following code:
?
1 2 3 4 5 6 7 8 9 10 11 12 |
library(RCurl) library(XML) library(RJSONIO) movieScoreapi <- function(x) { api <-
"https://api.douban.com/v2/movie/search?q={" url <- paste(api, x,
"}"
, sep =
""
) res <- getURL(url) reslist <- fromJSON(res) name <- reslist$subjects[[1]]$title score <- reslist$subjects[[1]]$rating$average return
(list(name = name, score = score)) } movieScoreapi(‘冰雪奇缘’)
|
Run successfully