Good afternoon,
I have a code that works for some forms on the web and I'm trying to reuse it on this site: link
However, my code can not find the form, it follows the code and the answer:
#library's
require(RCurl)
require(XML)
require(stringr)
require(plyr)
require(rvest)
require(xlsx)
require(dplyr)
#previa
info <- debugGatherer()
handle <- getCurlHandle(cookiejar = "",
followlocation = TRUE,
autoreferer = TRUE,
debugfunc = info$update,
verbose = TRUE,
httpheader = list(
from = "[email protected]",
'user-agent' = str_c(R.version$version.string,
", ", R.version$platform)
))
##função que mostra dados dos formulários (não funcionando)
xmlAttrsToDF <- function(parsedHTML, xpath) {
x <- xpathApply(parsedHTML, xpath, xmlAttrs)
x <- lapply(x, function(x) as.factor(t(x)))
do.call(rbind.fill, x)
}
#website
url <- "http://www.anbima.associados.rtm/titulos-publicos/estrutura-a-termo/tp-estrutura-termo.asp"
html_form <- getURL(url, curl = handle)
parsed_form <- htmlParse(html_form)
pgsession <-html_session(url)
pgform <-html_form(pgsession)[[4]]
pgform
<form> 'cz' (POST CZ.asp)
<input radio> 'escolha': 1
<input radio> 'escolha': 2
<input radio> 'saida': xls
<input radio> 'saida': csv
<input radio> 'saida': xml
<input radio> 'saida': txt
<input text> 'Dt_Ref':
<input button> '': Consultar
xmlAttrsToDF(parsed_form, "//fieldset")
res <- postForm(uri = str_c(url, 'CZ.asp'),
curl = handle,
style = "HTTPPOST",
"escolha" = "1",
"saida" = "xls",
"Dr_Ref" = "24032017")
Result after postForm:
Erro: Not Found