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, 2019 in Data Analytics by Sophie may
• 10,610 points
510 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, 2019 by Zulaikha
• 910 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, 2019 in Data Analytics by anonymous
574 views
+1 vote
2 answers

How to sort a data frame by columns in R?

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

answered Aug 21, 2019 in Data Analytics by anonymous
• 33,030 points
1,401 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 6, 2019 in Data Analytics by anonymous
13,625 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,660 points
7,507 views
+1 vote
3 answers

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$sym ...READ MORE

answered Jan 11, 2019 in Data Analytics by Tyrion anex
• 8,700 points
35,140 views
+1 vote
1 answer

Parallel programming In R using GPU

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

answered Feb 4, 2019 in Data Analytics by Tyrion anex
• 8,700 points
1,191 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 26, 2019 in Data Analytics by Sophie may
• 10,610 points
5,663 views
+1 vote
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, 2019 in Data Analytics by Zulaikha
• 910 points
691 views
0 votes
1 answer

Probabilities in R programming

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

answered May 27, 2019 in Data Analytics by Zulaikha
• 910 points
1,374 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP