用R填写表格后下载文件 [英] Download file after fill form with R

查看:40
本文介绍了用R填写表格后下载文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试访问一个网站,填写表格,然后将文件下载到我的计算机中,但我遇到了一些困难.

I am trying to access a website, fill the form and after that download the file in my computer, but I am having some hard time.

这是我现在的代码:

#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 this code returns an error after send the submit: Erro: Could not find possible submission target.

有人可以帮我吗?

推荐答案

为什么不只是:

library(httr)
library(xml2)

POST(url = "http://www.anbima.com.br/est_termo/CZ-down.asp", 
     body = list(escolha = "2", 
                 Idioma = "PT", 
                 saida = "xml", 
                 Dt_Ref_Ver = "20170221", 
                 Dt_Ref = "02/03/2017"), 
     encode = "form", verbose()) -> res

content(res, as="raw") %>% 
  rawConnection() %>% 
  read_xml() %>% 
  toString() %>% 
  cat()
## <?xml version="1.0" encoding="UTF-8"?>
## <CURVAZERO>
##   <DATA_REFERENCIA>02/03/2017</DATA_REFERENCIA>
##   <PARAMETROS>
##     <PARAMETRO Grupo="PREFIXADOS" B1="0,106326680464333" ## B2="1,73300184931697E-02" B3="4,45716446059779E-02" B4="-0,071256437528056" ## L1="3,54393138015703" L2="1,96450372343677"/>
##     <PARAMETRO Grupo="IPCA" B1="5,00834584018246E-02" B2="1,83058423633929E-02" ## B3="-0,111148039819161" B4="9,62384431553517E-02" L1="1,02213632049807" ## L2="0,804445046743235"/>
##   </PARAMETROS>
##   <ETTJ>
##     <VERTICES Vertice="126" IPCA="5,8934" Prefixados="10,9049" ## Inflacao="4,7325"/>
##     <VERTICES Vertice="252" IPCA="5,4995" Prefixados="10,0806" ## Inflacao="4,3422"/>
##     <VERTICES Vertice="378" IPCA="5,3689" Prefixados="9,8525" Inflacao="4,2551"/>
##     <VERTICES Vertice="504" IPCA="5,3527" Prefixados="9,8637" Inflacao="4,2818"/>
##     <VERTICES Vertice="630" IPCA="5,3773" Prefixados="9,9428" Inflacao="4,3325"/>
##     <VERTICES Vertice="756" IPCA="5,4088" Prefixados="10,0286" ## Inflacao="4,3827"/>
##     <VERTICES Vertice="882" IPCA="5,4335" Prefixados="10,1037" ## Inflacao="4,4295"/>
##     <VERTICES Vertice="1.008" IPCA="5,4476" Prefixados="10,1656" ## Inflacao="4,4742"/>
##     <VERTICES Vertice="1.134" IPCA="5,4514" Prefixados="10,2159" ## Inflacao="4,5181"/>
##     <VERTICES Vertice="1.260" IPCA="5,4471" Prefixados="10,2569" ## Inflacao="4,5613"/>
##     <VERTICES Vertice="1.386" IPCA="5,4368" Prefixados="10,2909" ## Inflacao="4,6038"/>
##     <VERTICES Vertice="1.512" IPCA="5,4226" Prefixados="10,3193" ## Inflacao="4,6448"/>
##     <VERTICES Vertice="1.638" IPCA="5,4062" Prefixados="10,3433" ## Inflacao="4,6838"/>
##     <VERTICES Vertice="1.764" IPCA="5,3888" Prefixados="10,3640" ## Inflacao="4,7208"/>
##     <VERTICES Vertice="1.890" IPCA="5,3712" Prefixados="10,3819" ## Inflacao="4,7552"/>
##     <VERTICES Vertice="2.016" IPCA="5,3539" Prefixados="10,3976" ## Inflacao="4,7873"/>
##     <VERTICES Vertice="2.142" IPCA="5,3374" Prefixados="10,4114" ## Inflacao="4,8169"/>
##     <VERTICES Vertice="2.268" IPCA="5,3217" Prefixados="10,4237" ## Inflacao="4,8442"/>
##     <VERTICES Vertice="2.394" IPCA="5,3070" Prefixados="10,4347" ## Inflacao="4,8692"/>
##     <VERTICES Vertice="2.520" IPCA="5,2933" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="2.646" IPCA="5,2806" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="2.772" IPCA="5,2687" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="2.898" IPCA="5,2578" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="3.024" IPCA="5,2477" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="3.150" IPCA="5,2383" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="3.276" IPCA="5,2296" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="3.402" IPCA="5,2215" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="3.528" IPCA="5,2139" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="3.654" IPCA="5,2068" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="3.780" IPCA="5,2003" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="3.906" IPCA="5,1941" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="4.032" IPCA="5,1883" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="4.158" IPCA="5,1828" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="4.284" IPCA="5,1777" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="4.410" IPCA="5,1729" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="4.536" IPCA="5,1683" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="4.662" IPCA="5,1640" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="4.788" IPCA="5,1599" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="4.914" IPCA="5,1560" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="5.040" IPCA="5,1523" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="5.166" IPCA="5,1488" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="5.292" IPCA="5,1454" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="5.418" IPCA="5,1423" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="5.544" IPCA="5,1392" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="5.670" IPCA="5,1363" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="5.796" IPCA="5,1335" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="5.922" IPCA="5,1309" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="6.048" IPCA="5,1283" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="6.174" IPCA="5,1259" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="6.300" IPCA="5,1235" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="6.426" IPCA="5,1212" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="6.552" IPCA="5,1191" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="6.678" IPCA="5,1170" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="6.804" IPCA="5,1150" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="6.930" IPCA="5,1130" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="7.056" IPCA="5,1112" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="7.182" IPCA="5,1094" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="7.308" IPCA="5,1076" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="7.434" IPCA="5,1059" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="7.560" IPCA="5,1043" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="7.686" IPCA="5,1027" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="7.812" IPCA="5,1012" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="7.938" IPCA="5,0997" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="8.064" IPCA="5,0983" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="8.190" IPCA="5,0969" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="8.316" IPCA="5,0956" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="8.442" IPCA="5,0943" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="8.568" IPCA="5,0930" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="8.694" IPCA="5,0918" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="8.820" IPCA="5,0906" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="8.946" IPCA="5,0894" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="9.072" IPCA="5,0883" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="9.198" IPCA="5,0872" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="9.324" IPCA="5,0861" Prefixados="" Inflacao=""/>
##     <VERTICES Vertice="9.450" IPCA="5,0851" Prefixados="" Inflacao=""/>
##   </ETTJ>
##   <CIRCULAR_3316>
##     <CIRCULAR Vertices="21" Taxa="12,1517"/>
##     <CIRCULAR Vertices="42" Taxa="11,8974"/>
##     <CIRCULAR Vertices="63" Taxa="11,6311"/>
##     <CIRCULAR Vertices="126" Taxa="10,9049"/>
##     <CIRCULAR Vertices="252" Taxa="10,0806"/>
##     <CIRCULAR Vertices="504" Taxa="9,8637"/>
##     <CIRCULAR Vertices="756" Taxa="10,0286"/>
##     <CIRCULAR Vertices="1.008" Taxa="10,1656"/>
##     <CIRCULAR Vertices="1.260" Taxa="10,2569"/>
##     <CIRCULAR Vertices="2.520" Taxa=""/>
##   </CIRCULAR_3316>
##   <ERROS>
##     <ERRO Titulo="LTN" SELIC="100000" Vencimento="01/04/2017" Erro="-0,0473"/>
##     <ERRO Titulo="LTN" SELIC="100000" Vencimento="01/07/2017" Erro="0,0236"/>
##     <ERRO Titulo="LTN" SELIC="100000" Vencimento="01/10/2017" Erro="-0,0057"/>
##     <ERRO Titulo="LTN" SELIC="100000" Vencimento="01/01/2018" Erro="0,0229"/>
##     <ERRO Titulo="LTN" SELIC="100000" Vencimento="01/04/2018" Erro="-0,0279"/>
##     <ERRO Titulo="LTN" SELIC="100000" Vencimento="01/07/2018" Erro="-0,0414"/>
##     <ERRO Titulo="LTN" SELIC="100000" Vencimento="01/10/2018" Erro="-0,0137"/>
##     <ERRO Titulo="LTN" SELIC="100000" Vencimento="01/01/2019" Erro="0,0053"/>
##     <ERRO Titulo="LTN" SELIC="100000" Vencimento="01/04/2019" Erro="-0,0023"/>
##     <ERRO Titulo="LTN" SELIC="100000" Vencimento="01/07/2019" Erro="0,0058"/>
##     <ERRO Titulo="LTN" SELIC="100000" Vencimento="01/01/2020" Erro="0,0078"/>
##     <ERRO Titulo="LTN" SELIC="100000" Vencimento="01/07/2020" Erro="-0,0368"/>
##     <ERRO Titulo="NTN-F" SELIC="950199" Vencimento="01/01/2018" Erro="-0,0042"/>
##     <ERRO Titulo="NTN-F" SELIC="950199" Vencimento="01/01/2019" Erro="0,0607"/>
##     <ERRO Titulo="NTN-F" SELIC="950199" Vencimento="01/01/2021" Erro="0,0076"/>
##     <ERRO Titulo="NTN-F" SELIC="950199" Vencimento="01/01/2023" Erro="-0,0329"/>
##     <ERRO Titulo="NTN-F" SELIC="950199" Vencimento="01/01/2025" Erro="0,0050"/>
##     <ERRO Titulo="NTN-F" SELIC="950199" Vencimento="01/01/2027" Erro="0,0153"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/05/2017" Erro="0,0685"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/08/2018" Erro="-0,0975"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/05/2019" Erro="0,0752"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/08/2020" Erro="0,0578"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/05/2021" Erro="0,0031"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/08/2022" Erro="-0,0951"/>
##     <ERRO Titulo="NTN-B" SELIC="760100" Vencimento="15/03/2023" Erro="-0,0404"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/05/2023" Erro="-0,0424"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/08/2024" Erro="0,0591"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/08/2026" Erro="-0,0297"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/08/2030" Erro="0,1078"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/05/2035" Erro="0,0220"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/08/2040" Erro="0,0272"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/05/2045" Erro="-0,0573"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/08/2050" Erro="-0,0344"/>
##     <ERRO Titulo="NTN-B" SELIC="760199" Vencimento="15/05/2055" Erro="0,0172"/>
##   </ERROS>
## </CURVAZERO>## 

这种数据最好用 XML 表示,因为其中有多个事物".

This data is better represented as XML since there are multiple "things" in it.

这篇关于用R填写表格后下载文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆