2017-08-17 9 views
0

thisウェブサイトでは、コード「539300」をトップ検索ボックスに入力して、ページから(new url)または一部のコンテンツ(Xpathを使用)を取得します。javascriptを投稿してRでウェブスクレイピングを行う

library(rvest); library(httr); library(RCurl) 

url <- "http://www.moneycontrol.com" 


res <- POST(url, body = list(search_str = "539300"), encode = "form") 

pg <- read_html(content(res, as="text", encoding="UTF-8")) 

html_node(pg, xpath = '//*[@id="nChrtPrc"]/div[3]/h1') 

これはエラー

{xml_missing} 
<NA> 
+0

スクラップしようとしているテーブルのスナップショットを提供できますか? –

+0

こんにちは、[新しいURLリンク](http://www.moneycontrol.com/india/stockpricequote/miscellaneous/akspintex/AKS01)< - 「// * [@ id = "nChrtPrc"]/div [ 3]/h1 ' - パスは "AK Spintex"です。 – Vasim

+1

_「moneycontrol.comの書面による許可なしに、ニュース記事、写真、ビデオ、その他のコンテンツの一部または全部を複製することは禁じられています。」_ – hrbrmstr

答えて

0

それともRCurlとXMLライブラリを使用することになります。

library(RCurl) 
library(XML) 

url <- "http://www.moneycontrol.com/india/stockpricequote/miscellaneous/akspintex/AKS01" 
curl <- getCurlHandle() 
html <- getURL(url,curl=curl, .opts = list(ssl.verifypeer = FALSE),followlocation=TRUE) 
doc <- htmlParse(html, encoding = "UTF-8") 
h1 <-xpathSApply(doc, "//*[@id='nChrtPrc']/div[3]/h1//text()") 
print(h1) 
関連する問題