I am trying to download a .csv file from https://www.bseindia.com/markets/equity/EQReports/MarketWatch.aspx by using R but it is not working.
I am posting screenshot with location of file that I am trying to download.
when I click on the image of the .csv file a file is downloading with the name "MarketWatch_14_00_2018.csv"
My goal is to read the file into R so I used the below command
MARKET_WATCH <- read.csv("MarketWatch_15_00_2018.csv", stringsAsFactors = F)
this worked fine but I wanted to automate this process that is read the file "MarketWatch_15_00_2018.csv" directly from web without clicking and downloading it manually, so I used the following command to achieve this task.
MARKET_WATCH_TEST <- read.csv("https://www.bseindia.com/markets/Equity/EQReports/MarketWatch.aspx?expandable=2/MarketWatch_17_00_2018.csv")
this command gave no errors but the data that was loaded into dataframe was not correct, it had some HTML code that got loaded into dataframe
So I tried downloading the file first, so that I can load it later, I used below command to download the file
downld <- getURL("https://www.bseindia.com/markets/Equity/EQReports/MarketWatch.aspx?expandable=2/MarketWatch_17_00_2018.csv? accessType=DOWNLOAD")
DATA <- read.csv (text = downld)
I checked the data the same HTML code is copied in both the dataframes this time i.e the file didn't load at all just the html text loaded into dataframe
I tried couple of other ways like using fread
and getURL
etc but none of that worked. Code that I used for loading the data is mentioned below.
dwnld <- fread("https://www.bseindia.com/markets/Equity/EQReports/MarketWatch.aspx?expandable=2/MarketWatch_17_00_2018.csv")
URL <- "https://www.bseindia.com/markets/equity/EQReports/MarketWatch.aspx/MarketWatch_17_00_2018.csv"
X <- getURL(URL)
Can someone please help me understand why the file is not properly loading into R environment when I am trying to load it directly from web where as it is loading fine after downloading the file to my local desktop.