Crawl Web data through Rcurl

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.