# if you get an error while importing, just use install.packages('jsonlite') and /or install.packages('stringr')
library(jsonlite)
library(stringr)
# the ieee doc url we're interested in
url <- 'http://ieeexplore.ieee.org/document/6875970/keywords'
# read the document as text, no HTML parsing at all
doc <- readLines(url)
# after inspecting it, we notice it's built with angular-js,
# and the data we need to extract is defined as a single javascript variable.
# so, we first find the id of the line which defines
# the javascript variable containing the tags
idx <- which(!is.na(str_match(doc, 'global.document.metadata=')))
# get the line ;-)
line <- doc[idx]
# since it's a javascript variable, we need to massage it
# a little to be able to read it as json.
# step 1: remove the "var global.document.metadata=" part (everything before the actual json)
line <- str_replace(line, '^[^{]*', '')
# step 2: remove the trailing ';' symbol
line <- str_replace(line, ';$', '')
# now we can parse the json data
df <- fromJSON(line)
# and get the information we need
df$keywords[df$keywords$type == 'IEEE Keywords',]$kwd[[1]]
df$keywords[df$keywords$type == 'INSPEC: Controlled Indexing',]$kwd[[1]]
df$keywords[df$keywords$type == 'INSPEC: Non-Controlled Indexing',]$kwd[[1]]
サンプル出力:
[1] "CTC incident datasets"
[2] "proactive spatiotemporal resource allocation"
[3] "predictive visual analytics"
[4] "community policing"
[5] "law enforcement"
あなたは*より少し具体的でした "しかし、それは動作しません!" * – Filburt
はい、もちろん!私が望むのは、地理空間分析、意思決定などのウェブサイトからすべてのキーワードを抽出することです。しかし、私がしたことは、「トークン化のエラー(css):予期しない文字/ 5番目の位置にあります。したがって、私のコードが私が期待していたものに合わないことを恐れています。私はR初心者であり、いくつかのRチュートリアル(Lego_moviesでもHTLMで書かれています)を見ています。私が間違っていない場合、私のウェブページはJavaScriptで書かれています。助けてくれてありがとう:) –
私はあなたのためにこれを再フォーマットすることを考えましたが、決して起こらないはずの '%>%a < - 'で何か不思議なことが起きました。それは、あなたが取りたいと思っているサイトは、利用規約を持っています... "ゲスト/メンバーのユーザーは、以下を行うことは許されません:[*] *電子メールやその他のファイル転送プロトコル、 IEEE Xploreの任意の部分*あなたが一度持っていればこの情報を使用することが許されているかどうかを検討したいかもしれません –