getForm mit get-Methode - wie umgehe ich die Umleitung?
-
21-12-2019 - |
Frage
Ich kämpfe mit dem getForm
und das Problem, meine Anfrage umzuleiten.Ich habe versucht zu experimentieren mit cookiefile
und followlocation
wie in anderen Themen im Stackoverflow, aber ohne Ergebnis.
Mein Code:
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
)
)
Habe ich Recht, dass ich den Inhalt der Umleitungsseite erhalte?Wenn ja, wie kann ich es umgehen?
Lösung
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)
Mit ein bisschen Überzeugungskraft sollte test2 hoffentlich die Ergebnisse enthalten
curl ist ein Handle, das über Anrufe hinweg bestehen bleibt.Einstellung cookiefile
weist RCurl an, die Cookies zu speichern.Sie können auf die Informationen im Curl-Handle zugreifen mit getCurlInfo(curl)
.Beispielsweise
> cat(getCurlInfo(curl)$cookielist)
korpus.pl FALSE / FALSE 0 PHPSESSID ark8hbi13e2c4qrp51aq51nj62
Der Aufruf von getForm setzt das wichtige Cookie PHPSESSID
.Die erste getURL führt zu:
> library(XML)
> htmlParse(test1)['//h3'][[1]]
<h3>This page will <a href="poliqarp.php">refresh</a> automatically in a second</h3>
Es sagt Ihnen, dass es wahrscheinlich automatisch mit Javascript aktualisiert wird, also müssen Sie diese Aktualisierung manuell durchführen, indem Sie einen weiteren Anruf tätigen.