2

If you go to the website https://www.myfxbook.com/members/iseasa_public1/rush/2531687 then click that dropdown box Export, then choose CSV, you will be taken to https://www.myfxbook.com/statements/2531687/statement.csv and the download (from the browser) will proceed automatically. The thing is, you need to be logged in to https://www.myfxbook.com in order to receive the information; otherwise, the file downloaded will contain the text "Please login to Myfxbook.com to use this feature".

I tried using read.csv to get the csv file in R, but only got that "Please login" message. I believe R has to simulate an html session (whatever that is, I am not sure about this) so that access will be granted. Then I tried some scraping tools to login first, but to no avail.

library(rvest)
login <- "https://www.myfxbook.com"
pgsession <- html_session(login)
pgform <- html_form(pgsession)[[1]]
filled_form <- set_values(pgform, loginEmail = "*****", loginPassword = "*****") # loginEmail and loginPassword are the names of the html elements
submit_form(pgsession, filled_form)

url <- "https://www.myfxbook.com/statements/2531687/statement.csv"
page <- jump_to(pgsession, url) # page will contain 48 bytes of data (in the 'content' element), which is the size of that warning message, though I could not access this content.

From the try above, I got that page has an element called cookies which in turns contains JSESSIONID. From my research, it seems this JSESSIONID is what "proves" I am logged in to that website. Nonetheless, downloading the CSV does not work.

Then I tried:

library(RCurl)
h <- getCurlHandle(cookiefile = "")
ans <- getForm("https://www.myfxbook.com", loginEmail = "*****", loginPassword = "*****", curl = h) 
data <- getURL("https://www.myfxbook.com/statements/2531687/statement.csv", curl = h)
data <- getURLContent("https://www.myfxbook.com/statements/2531687/statement.csv", curl = h)

It seems these libraries were built to scrape html pages and do not deal with files in other formats.

I would pretty much appreciate any help as I've been trying to make this work for quite some time now.

Thanks.

Denny Ceccon
  • 145
  • 9
  • 2
    Careful, many services contain a boilerplate text in their terms of service that forbid sharing credentials. I haven’t checked whether this site does, too. But be aware they might not like it.. – Konrad Rudolph Feb 15 '19 at 14:06
  • https://stackoverflow.com/a/40281845/8015575 might help you. With `RSelenium` you get a fully functional browser which you can use for login stuff, etc. – Ben373 Feb 15 '19 at 14:09
  • Thank you @KonradRudolph, I will cancel this email. – Denny Ceccon Feb 15 '19 at 16:13

0 Answers0