0

I'm trying to scrape options prices from the ASX with rvest and I'd like some help piping my code. I want to pipe and end up with a data frame.

The page at the link above has two tables, the first with share price information and the second with all options. When I run the following code I get a dataframe of the second table:

html <- read_html("http://www.asx.com.au/asx/markets/optionPrices.do?by=underlyingCode&underlyingCode=ANZ&expiryDate=&optionType=B")
nodes <- html_nodes(html, "table.options")
df <- html_table(nodes)[[2]]

But when I try to pipe that same code with the following:

html <- read_html("http://www.asx.com.au/asx/markets/optionPrices.do?by=underlyingCode&underlyingCode=ANZ&expiryDate=&optionType=B")
html %>% 
 html_nodes("table.options") %>% 
 html_table()[[2]]

I get an error reading 'Error in UseMethod("html_table") : no applicable method for 'html_table' applied to an object of class "NULL"'

Can anyone tell me what I'm doing wrong?

Rob
  • 26,989
  • 16
  • 82
  • 98
Dom
  • 1,043
  • 2
  • 10
  • 20
  • See also [here](https://stackoverflow.com/questions/27100678/how-to-extract-subset-an-element-from-a-list-with-the-magrittr-pipe) – erocoar Jan 03 '18 at 00:49
  • At least have the decency to inform potential answerers that you're willing to put them at risk of civil & criminal penalties for your financial gain. http://www.asx.com.au/about/terms-use.htm – hrbrmstr Jan 03 '18 at 02:36

1 Answers1

0

If you want to index that directly you would have to index in a seperate pipe like so

read_html("http://www.asx.com.au/asx/markets/optionPrices.do?by=underlyingCode&underlyingCode=ANZ&expiryDate=&optionType=B") %>%
html_nodes("table.options") %>%
html_table() %>%
.[[2]]

where . acts as the output of the previous pipe.

EmilHvitfeldt
  • 2,555
  • 1
  • 9
  • 12