R下载数据

在看余光创教授的一个包,把一些学到的内容记录下来.

1 使用命令打开网页

  url <- 'https://baidu.com'
  utils::browseURL(url)

2 下载2019 new-Coronaverus数据

 url <- 'https://view.inews.qq.com/g2/getOnsInfo?name=disease_h5&callback=1580373566110'
  x <- suppressWarnings(readLines(url, encoding = "UTF-8"))
  x <- sub(pattern = "^\\d+\\(", replacement = "", x = x)
  x <- sub(pattern = "\\)$", replacement = "", x = x)
  y <- jsonlite::fromJSON(txt = x)
  z <- jsonlite::fromJSON(txt = y$data)

z是一个list,里面包含了所有的信息.

names(z)
##  [1] "lastUpdateTime"     "chinaTotal"         "chinaAdd"          
##  [4] "isShowAdd"          "showAddSwitch"      "areaTree"          
##  [7] "chinaDayList"       "chinaDayAddList"    "dailyNewAddHistory"
## [10] "dailyHistory"       "wuhanDayList"       "articleList"
z$chinaTotal
## $confirm
## [1] 78196
## 
## $heal
## [1] 29858
## 
## $dead
## [1] 2718
## 
## $nowConfirm
## [1] 45620
## 
## $suspect
## [1] 2491
## 
## $nowSevere
## [1] 8752
z$chinaAdd
## $confirm
## [1] 6
## 
## $heal
## [1] 83
## 
## $dead
## [1] 0
## 
## $nowConfirm
## [1] -77
## 
## $suspect
## [1] 0
## 
## $nowSevere
## [1] 0
z$lastUpdateTime
## [1] "2020-02-27 00:32:14"
Avatar
Xiaotao Shen
Postdoctoral Research Fellow

Metabolomics, Multi-omics, Bioinformatics, Systems Biology.

Related

Next
Previous
comments powered by Disqus