我正在尝试使用httr和purrr执行多个POST请求。每个POST请求都必须更改页面参数。有了for循环,我会这样做:
library(httr)
library(xml2)
library(stringr)
url<-"http://busca.tjsc.jus.br/jurisprudencia/buscaForm.do"
a<-GET(url)
body<-list(q = "", only_ementa = "", frase = "", excluir = "",
qualquer = "", `NA` = NA_character_, prox1 = "", prox2 = "",
proxc = "", sort = "dtJulgamento desc", ps = "50", busca = "avancada",
pg = "1", flapto = "1", radio_campo = "integra", `categoria[]` = "acordaos",
faceta = "false")
body[[1]]<-"indulto"
url2<-"http://busca.tjsc.jus.br/jurisprudencia/buscaajax.do?&categoria=acordaos"
b<-POST(url2,body=body,encode="form",set_cookies(unlist(a$cookies)))
pages<- b %>%
httr::content() %>%
xml_find_all("//*[@class='texto_resultados']") %>%
xml_text() %>%
str_extract("\\d+") %>%
as.numeric() %>%
`/`(50) %>%
ceiling()
c<-NULL
for(i in 1:pages){
body[[13]]<-i
d<-url2 %>% POST(body=body,encode="form",set_cookies(unlist(a$cookies))) %>%
httr::content() %>%
xml_find_all("//*[@id='coluna_principal']/div/div[3]/a/@href") %>%
xml_text() %>%
paste0("http://busca.tjsc.jus.br/jurisprudencia/",.)
c<-c(c,d)
}
有人可以帮我解决如何使用purrr :: map吗?