全て
私は、Google 検索データ マイニング用のRプログラムに取り組んでいます。
これまでのところ、繁体字中国語のエンコーディングの問題を除けば、私のコードは問題なく動作します。私はLinux環境で作業しています...
Google <- function(input)
{
require(XML)
require(stringr)
require(RCurl)
hits <- GoogleHits(input)
if( hits >= 1000){
start.num = seq(0,900,100)
}else if(hits < 1000){
start.num = seq(0,hits,100)
}
for(i in 1:length(start.num)){
start = start.num[i]
url <-paste("https://www.google.com/search?as_epq=",input,
"&as_occt=title&num=100&ie=UTF-8&start=",start, sep = "")
CAINFO = paste(system.file(package="RCurl"), "/CurlSSL/ca-bundle.crt", sep = "")
script <- getURL(url, followlocation = TRUE, cainfo = CAINFO)
# using htmlParse() to re-organize the whole structure
# the Chinese encoding shows quite well here
# (but the structure is not a vector)
doc <- htmlParse(script)
# Wanna extract out the searched keyword
# which is tagged by "<b>keyword</b>"
# here, I take the keyword "統計" for example
extract <- str_extract_all(html_str, "<b>統計</b>")
# here is the problem... which extract only takes a vector as an argument
# so below will return an error
print (extract)
}
}
だから、私が遭遇した問題はすべてコメントに含まれています。
1) htmlParse()を使用しない場合、抽出されたデータを認識された漢字で表示できません。
2) データをベクトルに変換しようとした場合 ( script <- lapply(url, getURL)を適用して)、str_extract_all()メソッドを使用できますが、エンコードの問題が発生します...
なお、ここでいう中国語とは繁体字中国語のことです
コメントや提案は本当にありがたいです!
前もって感謝します。