2016-10-18 6 views
0

まず、多くの感謝を掻き取り、R - ウェブあなたの助けとあなたの検討のため

私はあなたが1つのウェブサイトになったら、このページhttp://ieeexplore.ieee.org/document/6875970/keywordsから何かを抽出したい、私は に関連する情報をスクラップウェブに興味を持っています - IEEEキーワード - INSPEC:制御されたインデックス - INSPEC:非制御インデックス

install.packages("rvest") 
library(rvest) 
keywords<-read_html("http://ieeexplore.ieee.org/document/6875970/keywords") 

keywords %>% 
a<-html_node(lego_movie,"text/javascript") %>% 
html_text(a) 

しかし、それは動作しません!

私を助けてもらえますか?

ありがとうございます!

+0

あなたは*より少し具体的でした "しかし、それは動作しません!" * – Filburt

+0

はい、もちろん!私が望むのは、地理空間分析、意思決定などのウェブサイトからすべてのキーワードを抽出することです。しかし、私がしたことは、「トークン化のエラー(css):予期しない文字/ 5番目の位置にあります。したがって、私のコードが私が期待していたものに合わないことを恐れています。私はR初心者であり、いくつかのRチュートリアル(Lego_moviesでもHTLMで書かれています)を見ています。私が間違っていない場合、私のウェブページはJavaScriptで書かれています。助けてくれてありがとう:) –

+2

私はあなたのためにこれを再フォーマットすることを考えましたが、決して起こらないはずの '%>%a < - 'で何か不思議なことが起きました。それは、あなたが取りたいと思っているサイトは、利用規約を持っています... "ゲスト/メンバーのユーザーは、以下を行うことは許されません:[*] *電子メールやその他のファイル転送プロトコル、 IEEE Xploreの任意の部分*あなたが一度持っていればこの情報を使用することが許されているかどうかを検討したいかもしれません –

答えて

1
# 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"         
+0

それは働いています! –

+0

ありがとうございました!私ができるときはいつでも助けてくれてうれしいです:) –

+0

本当にありがとう!とても大変役に立ちました!私はいつかファイナンスや統計の分野でお手伝いできるかどうか教えてください:) –

関連する問題