-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwebScrapping.R
More file actions
45 lines (34 loc) · 1.63 KB
/
webScrapping.R
File metadata and controls
45 lines (34 loc) · 1.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#### Microsoft NASDAQ Example ####
library(XML)
library(httr)
library(xlsx)
library(data.table)
#Iteration vectors
dateindex=c(0:7)
optionChainPages=c(0:5)
greekPages=c(0:8)
#Function for Getting the option chain data and Writing to excel file
for (dateindex in c(0:7)) {
for (page in c(0:5)) {
#Define the URL
optionChain= paste("http://www.nasdaq.com/symbol/goog/option-chain?dateindex=",dateindex,"&page=",page)
#Get table data
option_Chain_Table= readHTMLTable(optionChain, which = 6)
#Write data into csv file
write.csv(option_Chain_Table, paste("C:/Users/sparta/Desktop/R/Microsoft/optionchain/option_Chain_Table_",dateindex,".csv"), append = T)
#Remove null values
na.omit(paste("C:/Users/sparta/Desktop/R/Microsoft/optionchain/option_Chain_Table_",dateindex,".csv"))
}
#Function for Getting the greek data and Writing to excel file
for (page in c(0:8)) {
#Define the URLs
greeks= paste("http://www.nasdaq.com/symbol/goog/option-chain/greeks?dateindex=",dateindex,"&page=",page)
#Get table data
greeks_Table= readHTMLTable(greeks, which = 6)
#Write data into csv files
write.csv(greeks_Table, "C:/Users/sparta/Desktop/R/Microsoft/greek/greeks_Table_",dateindex,".csv")
write.table(greeks_Table, file ="C:/Users/sparta/Desktop/R/Microsoft/greek/greeks_Table_",dateindex,".csv", append = T )
#Remove null values
na.omit(paste("C:/Users/sparta/Desktop/R/Microsoft/greek/greeks_Table_",dateindex,".csv"))
}
}