Home > Blockchain >  Xpath not "seeing" table in Rvest
Xpath not "seeing" table in Rvest

Time:10-06

I am attempting to scrape table in this website. I have done it in several website but can't scrape in this website. Does it have anything to do with the fact that the table is generated and not static? Here is my code:

library(tidyverse) 
library(rvest)

link <- "https://portal.vietcombank.com.vn/Personal/TG/Pages/ty-gia.aspx?devicechannel=default" 
webpage <- read_html(link) 
webpage %>% 
    html_nodes(xpath = "//*[@class = 'tbl-01 rateTable']") %>% 
    html_table()

Thank all very much

CodePudding user response:

The data actually is present in another link which can be found out by looking under Networks tab in the browser.

library(rvest)

url <- 'https://portal.vietcombank.com.vn/UserControls/TVPortal.TyGia/pListTyGia.aspx?txttungay=5/10/2021&BacrhID=1&isEn=False'
data <- url %>% read_html %>% html_table() %>% .[[1]]
data

#   `Ngoại tệ`        `Ngoại tệ` Mua       Mua          Bán      
#   <chr>             <chr>      <chr>     <chr>        <chr>    
# 1 Tên ngoại tệ      Mã NT      Tiền mặt  Chuyển khoản Bán      
# 2 AUSTRALIAN DOLLAR AUD        16,146.00 16,309.09    16,820.59
# 3 CANADIAN DOLLAR   CAD        17,613.63 17,791.55    18,349.54
# 4 SWISS FRANC       CHF        23,991.41 24,233.75    24,993.78
# 5 YUAN RENMINBI     CNY        3,459.86  3,494.81     3,604.96 
# 6 DANISH KRONE      DKK        -         3,489.44     3,620.54 
# 7 EURO              EUR        25,758.61 26,018.80    27,099.20
# 8 POUND STERLING    GBP        30,155.61 30,460.21    31,415.53
# 9 HONGKONG DOLLAR   HKD        2,849.58  2,878.36     2,968.63 
#10 INDIAN RUPEE      INR        -         304.65       316.60   
# … with 11 more rows
  • Related