Web scraping with R using rvest for financial website - r

I am trying to scrape data table from following website using R, but it is not returning any value. I am using SelectorGadget to get the nodes detail.
library(rvest)
url = "http://www.bursamalaysia.com/market/derivatives/prices/"
text <- read_html(url) %>%
html_nodes("td") %>%
html_text()
output:
text
character(0)
I would appreciate any kind of help. Thank you!

Related

Rvest and xpath returns misleading information

I am struggling with some scraping issues, using rvest and xpath.
The objective is to scrape the following page
https://www.barchart.com/futures/quotes/BT*0/futures-prices
and to extract the names of the futures
BTF21
BTG21
BTH21
etc for the full list of names.
The xpath for those variables seem to be xpath='//a'.
The following code provides no information of relevance, thus my query
library(rvest)
url <- 'https://www.barchart.com/futures/quotes/BT*0'
valuation_col <- url %>%
read_html() %>%
html_nodes(xpath='//a')
value <- valuation_col %>% html_text()
Any hint to proceed further to get the information would be much needed. Thanks in advance!

Problem with scraping news headlines in R

I am trying to scrape news headlines in R. Here is the sample code I have written. However, it is giving me a null set. Can someone tell me where am I going wrong?
library(tidyverse)
library(stringr)
library(rvest)
news_url1 <- "https://www.washingtonpost.com/newssearch/?query=economy&sort=Relevance&datefilter=All%20Since%202005&startat=0#top"
news_html1 <- read_html(as.character(news_url1))
news_html1 %>% html_nodes(".pb-feed-headline")%>% html_text()

Scraping a table from reddit in R

I am trying to scrape a table from reddit in R. Here is the link: https://old.reddit.com/r/hiphopheads/comments/9nocy8/twenty_one_pilots_trench_sells_170k_first_week/
I am trying to scrape the main table in the post. Here is my code:
library(rvest)
url <- "https://old.reddit.com/r/hiphopheads/comments/9nocy8/twenty_one_pilots_trench_sells_170k_first_week/"
albums <- url %>%
read_html() %>%
html_nodes(xpath ='//*[#id="form-t3_9nocy8ire"]/div/div/table') %>%
html_table()
albums
The issue is, this keeps returning me a list of 0. Any help on scraping this properly would be appreciated. Thanks!

Scraping dynamic information in R

I'm trying to use an xpath to scrape a figure I need on this website
I need these two numbers
So far I'm having no luck. Any help appreciated.
Does it need to be xPath? You can get it with:
library(rvest)
page <- read_html("http://www.myfxbook.com/community/outlook/EURUSD")
page %>% html_nodes("#leftColumn td:nth-child(4)") %>% html_text()

scraping tables with rvest in R

I'm attempting to scrape the table featuring trading data from this website: https://emma.msrb.org/IssuerHomePage/Issuer?id=F5FDC93EE0375953E043151E0A0AA7D0&type=M
This should be a rather simple process, but I run this code:
library(rvest)
url <- "https://emma.msrb.org/IssuerHomePage/Issuer?
id=F5FDC93EE0375953E043151E0A0AA7D0&type=M"
deals <- url %>%
read_html() %>%
html_nodes(xpath='//*[#id="lvTrades"]') %>%
html_table()
deals <- deals[[1]]
and I get the following error:
Error in deals[[1]] : subscript out of bounds
On top of this, it seems the scrape isn't returning any text. Any ideas on what I'm doing wrong? Sorry if this seems a little elementary, I'm relatively new to this scraping stuff.

Resources