0

I wanted to extract only table values from the following link. url<-"https://www.ds-norden.com/drycargo/fleetlist/"

I was trying the following code but I am not getting my desired output

library(rvest)
url <- "https://www.scorpiobulkers.com/our-fleet/"
webpage<-read_html(url)
rank_data_html<- html_node(webpage,".col-main")
rank_data<-html_text(rank_data_html)
head(rank_data)

from this code, I was getting the whole text of the webpage. I just wanted the fleet list which in the table of the webpage and store that as df in R.

barny
  • 5,280
  • 4
  • 16
  • 21
xyz
  • 77
  • 7

1 Answers1

1
library(rvest)

url <- "https://www.scorpiobulkers.com/our-fleet/"
webpage<-read_html(url)

rank_data <- 
  webpage %>% 
  html_node("table") %>% 
  html_table()

head(rank_data)
#>      Vessel Name Year Built (1) Yard (2) Vessel Type
#> 1 NA   SBI Bravo           2015    Nacks    Ultramax
#> 2 NA  SBI Athena           2015  Chengxi    Ultramax
#> 3 NA SBI Antares           2015    Nacks    Ultramax
#> 4 NA  SBI Cronos           2015  Imabari    Ultramax
#> 5 NA     SBI Leo           2015    Dacks    Ultramax
#> 6 NA    SBI Echo           2015  Imabari    Ultramax
Iaroslav Domin
  • 2,370
  • 7
  • 17
  • @laroslav Domin, I am applying same code for this webpage https://www.starbulk.com/gr/en/fleet-details/ but I am getting an error (Error in UseMethod("html_table") : no applicable method for 'html_table' applied to an object of class "xml_missing") can you please suggest thanks in advance – xyz Nov 27 '19 at 05:50