GetForm con Get Method - How to Bypassare il reindirizzamento?
-
21-12-2019 - |
Domanda
Sto lottando con il getForm
e il problema di reindirizzare la mia query.Ho provato a sperimentare cookiefile
e followlocation
come in altri argomenti in Stackoverflow ma senza alcun risultato.
Il mio codice:
getForm("http://korpus.pl/poliqarp/poliqarp.php",
query = "pies", corpus = "2", showMatch = "1",showContext = "3",
leftContext = "5", rightContext = "5", wideContext = "50", hitsPerPage = "10",
.opts = curlOptions(
verbose = TRUE,
followlocation=TRUE
)
)
.
Sono giusto che sto ottenendo il contenuto della pagina di reindirizzamento?Se sì, come posso bypassare?
Soluzione
curl = getCurlHandle(cookiefile = "", verbose = TRUE, followlocation=TRUE)
getForm("http://korpus.pl/poliqarp/poliqarp.php",
query = "pies", corpus = "2", showMatch = "1",showContext = "3",
leftContext = "5", rightContext = "5", wideContext = "50", hitsPerPage = "10",
.opts = curlOptions(
verbose = TRUE,
followlocation=TRUE
)
, curl = curl)
test1 <- getURL("http://korpus.pl/poliqarp/poliqarp.php", curl = curl)
test2 <- getURL("http://korpus.pl/poliqarp/poliqarp.php", curl = curl)
.
Con un po 'di persuasione test2, si spera che debba contenere i risultati
Curl è una maniglia che persisterà attraverso le chiamate.L'impostazione cookiefile
dice a RCurl di memorizzare i cookie.
È possibile accedere alle informazioni nell'impugnatura arricciatura utilizzando getCurlInfo(curl)
.Ad esempio
> cat(getCurlInfo(curl)$cookielist)
korpus.pl FALSE / FALSE 0 PHPSESSID ark8hbi13e2c4qrp51aq51nj62
.
La chiamata GetForm imposta l'importante cookie PHPSESSID
.Il primo Geturl si traduce in:
> library(XML)
> htmlParse(test1)['//h3'][[1]]
<h3>This page will <a href="poliqarp.php">refresh</a> automatically in a second</h3>
.
Ti dice che si aggiornerà automaticamente con JavaScript, quindi è necessario eseguire questo aggiornamento manualmente emettendo un'altra chiamata.