質問

私は苦労しています getForm そして、私のクエリをリダイレクトする問題。私は実験しようとしました cookiefilefollowlocation Stackoverflowの他のトピックと同様ですが、結果はありません。

私のコード:

  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 = 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)

説得test2のビットでうまくいけば、結果が含まれている必要があります

curlは、呼び出し間で永続化されるハンドルです。設定 cookiefile クッキーを保存するようにRCurlに指示します。Curlハンドルの情報には、次を使用してアクセスできます getCurlInfo(curl).例えば

> cat(getCurlInfo(curl)$cookielist)
korpus.pl   FALSE   /   FALSE   0   PHPSESSID   ark8hbi13e2c4qrp51aq51nj62

GetForm呼び出しは、重要なcookieを設定します PHPSESSID.最初のgetURLは次のようになります:

> library(XML)
> htmlParse(test1)['//h3'][[1]]
<h3>This page will <a href="poliqarp.php">refresh</a> automatically in a second</h3> 

おそらくjavascriptで自動更新されるため、別の呼び出しを発行して手動でこの更新を行う必要があります。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top