首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >getForm -如何发送特殊字符?

getForm -如何发送特殊字符?
EN

Stack Overflow用户
提问于 2014-04-13 13:02:30
回答 1查看 101关注 0票数 1

我有一个用Rcurl编写的小脚本,它把我和波兰语语料库连接起来,询问目标词的频率。但是,此解决方案仅适用于标准字符。如果我用指甲油字母问起这个词。(“ę”,“ą”)它的返回不匹配。输出日志显示脚本没有正确地传输url入口中的修饰字符。

我的剧本:

代码语言:javascript
复制
#slowo = word;
wordCorpusChecker<- function (slowo, korpus=2) {
#this line help me bypass the redirection page after calling for specific word 
curl = getCurlHandle(cookiefile = "", verbose = TRUE, 
                       followlocation=TRUE, encoding = "utf-8")
#standard call for submitting html form
 getForm("http://korpus.pl/poliqarp/poliqarp.php",
          query = slowo, corpus = as.character(korpus), showMatch = "1",
          showContext = "3",leftContext = "5", rightContext = "5", 
          wideContext = "50", hitsPerPage = "10", 
          .opts = curlOptions(
            verbose = T,
            followlocation=TRUE,
            encoding = "utf-8"
          )
          , curl = curl)
#In test2 there is html of page where I can find information I'm interested in 
  test1 <- getURL("http://korpus.pl/poliqarp/poliqarp.php", curl = curl)
  test2 <- getURL("http://korpus.pl/poliqarp/poliqarp.php", curl = curl)
#"scrapping" the frequency from html website 
 a<-regexpr("Found <em>", test2)[1]+
        as.integer(attributes(regexpr("Found <em>", test2)))
      b<-regexpr("</em> results<br />\n", test2)[1] - 1
      c<-a:b
      value<-substring(test2, c[1], c[length(c)])
      return(value)

    }

#if you try this you will get nice result about "pies" (dog) frequency in polish corpus 
    wordCorpusChecker("pies")

#if you try this you will get no match because  of the special characters 
    wordCorpusChecker("kałuża")

#the log from `verbose`: 

    GET /poliqarp/poliqarp.php?query=ka%B3u%BFa&corpus=2&showMatch=1&showContext=3&leftContext=5&rightContext=5&wideContext=50&hitsPerPage=10

我试图指定encoding选项,但正如手册所述,它指的是查询的结果。我正在用curlUnescape做实验,但没有取得积极的结果。敬请指教。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2014-04-13 13:14:51

一种解决方案是指定utf编码,例如

代码语言:javascript
复制
> "ka\u0142u\u017Ca"
[1] "kałuża"
wordCorpusChecker("ka\u0142u\u017Ca")

[1] "55"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/23043078

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档