我想用R語言將https://bitinfocharts.com上的tweet的成交量圖表中的資料抓取到一個資料檔案中。我是一個新手,在網上找了很多資料后,除了請您幫忙,我沒有別的選擇。我在論壇上發現了同樣的問題,但它是針對python的(如何從https://bitinfocharts.com的圖表中抓取資料)
問題中的圖表是以下內容。https://bitinfocharts.com/comparison/decred-tweets.html#alltime
我正在尋找一個資料表,以每個日期和該日相應的推文數量為列。
我希望你的經驗能夠幫助我
我希望你的經驗能夠幫助我。
uj5u.com熱心網友回復:
這段代碼應該有助于提取你需要的資料:
這段代碼應該有助于提取你需要的資料:
library('rvest'/span>)
library('stringr')
url <- 'https://bitinfocharts.com/comparison/decred-tweets.html#alltime'
webpage <- read_html(url)
res <- str_match(webpage, 'new Dygraph(document. getElementById("container"),s*(.*?)s*,{labels')。
res[,/span>2]
做完這些后,你應該決議res[,2],并根據你的需要對其進行轉換。
uj5u.com熱心網友回復:
新的Dyagraph部分來自于頁面源代碼。如果你在頁面源中搜索它(view-source:https://bitinfocharts.com/comparison/decred-tweets.html在你的瀏覽器中),你會注意到它。基本上,網站根據這些資料創建了圖表。 要決議矩陣,你需要首先洗掉字串中的 "new Date(") "部分,然后使用json庫決議完整的字串。
以下是完整的代碼,應該可以幫助你做到這一點:
library('rvest')
library('stringr')
library('jsonlite')
url <- 'https://bitinfocharts.com/comparison/decred-tweets.html#alltime'
webpage <- read_html(url)
res <- str_match(webpage, 'new Dygraph(document. getElementById("container"),s*(.*?)s*,{labels')。
res[,2] < - gsub("new Date(", "。 res[,2])
res[,2] < - gsub("/span>, "/span>。 res[,2])
document < - fromJSON(txt=res[。 2])
檔案
print(document[1。 1])
print(document[1。 2])
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/320244.html
標籤:
上一篇:InternetExplorer在無頭模式下無法與Selenium一起作業[使用headless_ie_selenium]
