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,330 points
8 views

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
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
• 640 points

Related Questions In Data Analytics

0 votes
1 answer

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

Use the dplyr package that R provides: library(dplyr) df1 ...READ MORE

answered Apr 25 in Data Analytics by Sophie may
• 9,330 points
25 views
0 votes
1 answer

How to sort a data frame by columns in R?

You can just use the order function ...READ MORE

answered Apr 10, 2018 in Data Analytics by darklord
• 6,140 points
60 views
0 votes
1 answer

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

dplyr added versions for group_by. This allows you ...READ MORE

answered Apr 12, 2018 in Data Analytics by CodingByHeart77
• 3,680 points

edited Apr 12, 2018 by CodingByHeart77 1,896 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,550 points
518 views
0 votes
1 answer

How to change the value of a variable using R programming in a data frame?

Try this: df$symbol <- as.character(df$symbol) df$symbol[df$symb ...READ MORE

answered Jan 11 in Data Analytics by Tyrion anex
• 8,280 points
55 views
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,280 points
45 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,330 points
15 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
• 640 points
10 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
• 640 points
14 views

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.