3
I’m trying to access a site, fill out your form and download the file, but I’m encountering some difficulties.
That’s my code so far:
#library's
require(rvest)
#website
url <- ("http://www.anbima.com.br/est_termo/Curva_Zero.asp")
pgsession <- html_session(url)
pgform <-html_form(pgsession)[[1]]
param <- set_values(pgform,
"escolha" = "2",
"Dt_Ref" = Sys.Date()
)
submit <- submit_form(pgsession, form = param, "Consultar")
But it returns an error when sending Submit: Erro: Could not find possible submission target.
Can someone help me?
The problem in Submit, eh that the form does not contain a button "Submit", here I solved the problem by creating a "fake Submit" in the form, but tested here and although the request worked, did not download the file... Probably need some other step to download
– Icaro Bombonato
I put the code with Submit working on a gist, but as I said, I’m only getting the feedback from Submit and not a file for donwload. But the mistake you’re making in the question, it doesn’t happen anymore if you do this... If this helps and solves your problem, I will post this comment in response... https://gist.github.com/ibombonato/11507d776d1042f80ca59cd31509afd3
– Icaro Bombonato
But do you have any idea how to pull this download? If it was on a site with the Ubmit button, what would you do? I’m looking for something here
– Danilo Imbimbo
Looking at the source code, has a javscript and I saw that the form needs to be changed and contain the url point to
CZ-down.asp
instead ofCurva_zero.asp
after this, it seems to me that the file is returned in the "Answer" of the request in raw format, but I don’t know exactly how to convert it to excel :- I would have to do a search to find out if it is possible to do this... I imagine it is necessary to create a connection, read the file through it and then save the same.– Icaro Bombonato
Replaces . Curva_zero.Asp by CZ-down.Asp and using the download.file() function worked. It was much simpler than I imagined, but that’s it, thanks friend!
– Danilo Imbimbo
If possible, put the complete code as the answer, so others can see the entire solution you used.
– Icaro Bombonato