Scraping columns from a website by using R Programming

0 votes

This is the code I'm using:

library(rvest)
library(dplyr)
url="http://relationalstocks.com/showinsiders.php?date=2017-09-15&buysell=buysell"
url_html<-read_html(url)
SharesTraded_html=html_nodes(url_html,'td:nth-child(6)')
SharesTraded=html_text(SharesTraded_html)
SharesTraded=as.numeric(gsub(",",'',SharesTraded))
AvgPriceDollars_html=html_node(url_html,'td:nth-child(7)')
AvgPriceDollars=html_text(AvgPriceDollars_html)
AvgPriceDollars
Jun 7 in Data Analytics by Sophie may
• 9,870 points
36 views

1 answer to this question.

0 votes

Here's an example, use the html_table :

library(rvest)
library(dplyr)
url <- read_html("url")
tb <- url %>% 
  html_node("#insidertab") %>%
  html_nodes("table") %>%
  html_table(fill = TRUE) %>%
  as.data.frame()

str(tb)
'data.frame':   253 obs. of  9 variables:
  $ Reported.Time: chr  "2017-09-15 21:00:47" "2017-09-15 20:11:26" "2017-09-15 20:11:26" "2017-09-15 20:10:27" ...
$ Tran.        : chr  "2017-09-12  Purchase" "2017-09-13  Sale" "2017-09-14  Sale" "2017-09-15  Sale" ...
$ Company      : chr  "Double Eagle Acquisition Corp." "PHIBRO ANIMAL HEALTH CORP" "PHIBRO ANIMAL HEALTH CORP" "Guidewire Software, Inc." ...
$ Ticker       : chr  "EAGL" "PAHC" "PAHC" "GWRE" ...
$ Insider      : chr  "SAGANSKY JEFFREYChief Executive Officer, Director, 10% owner" "Johnson Richard GChief Financial Officer" "Johnson Richard GChief Financial Officer" "Roza ScottChief Business Officer" ...
$ Shares.Traded: chr  "30,000" "15,900" "39,629" "782" ...
$ Avg.Price    : chr  "$10.05" "$36.46" "$36.23" "$78.20" ...
$ Value        : chr  "$301,500" "$579,714" "$1,435,758" "$61,152" ...
$ Filing       : logi  NA NA NA NA NA NA ...
answered Jun 7 by Zulaikha
• 870 points

Related Questions In Data Analytics

0 votes
2 answers

How can I group a set of values by column using R programming?

Try this , Employee %>% group_by(EmpID) %>% mutate(SumSalary ...READ MORE

answered Aug 14 in Data Analytics by anonymous
52 views
0 votes
2 answers

How to sort a data frame by columns in R?

You can use dplyr function arrange() like ...READ MORE

answered Aug 21 in Data Analytics by anonymous
• 32,260 points
164 views
0 votes
2 answers

How to use group by for multiple columns in dplyr, using string vector input in R?

data = data.frame(   zzz11def = sample(LETTERS[1:3], 100, replace=TRUE),   zbc123qws1 ...READ MORE

answered Aug 5 in Data Analytics by anonymous
3,809 views
0 votes
1 answer

Extracting numeric columns from a data.frame - R

You can use the select_if() function from ...READ MORE

answered May 4, 2018 in Data Analytics by Bharani
• 4,560 points
2,008 views
0 votes
2 answers
0 votes
1 answer

Parallel programming In R using GPU

Check out the CRAN Task View on High-Performance ...READ MORE

answered Feb 4 in Data Analytics by Tyrion anex
• 8,310 points
80 views
0 votes
1 answer

R programming: Naming the output file using a variable

Use the paste command: write.csv(max.hsi, paste0("Index_", i,".csv" ...READ MORE

answered Mar 25 in Data Analytics by Sophie may
• 9,870 points
41 views
0 votes
1 answer
0 votes
1 answer

Changing variable values using R programming

This should work: df$symbol <- as.character(df$symbol) df$symbol[df$symbol == "ABCD.BO"] ...READ MORE

answered May 27 in Data Analytics by Zulaikha
• 870 points
32 views
0 votes
1 answer

Probabilities in R programming

This should work: poker_face <- replicate(1000, sample(poker, size ...READ MORE

answered May 27 in Data Analytics by Zulaikha
• 870 points
95 views