私はこれを一日中解決しようとしていましたが、解決策を見つけることができません。助けてください !! だからウェブスクレイピングを学ぶために、私はこのウェブサイト上で練習してきた:Rselenium web scraping:関数として適用
https://www.net-a-porter.com/fr/fr/Shop/Designers/Fendi
目標は、すべての製品の価格をこすりすることです。私は204個の値の一覧(価格は私が望む結果を、得た本とそう
option <- remDr$findElement(using = 'xpath', "//*/option[@value = 'view_all']")
option$clickElement()
priceNodes <- remDr$findElements(using = 'css selector', ".price")
price<-unlist(lapply(priceNodes, function(x){x$getElementText()}))
price<-gsub("€","",price)
price<-gsub(",","",price)
price <- as.numeric(price)
: だから、このウェブサイトおよび他のインターネットユーザーにressourcesのおかげで、私は完璧に動作し、このコードを作りました)。 ここでは、この関数を住所リスト(この場合は他のブランド)に適用するために、このプロセス全体を関数に変換したいと考えています。 そして、明らかにそれは動作しませんでした...:
FPrice <- function(x) {
url1 <- x
remDr <- rD$client
remDr$navigate(url1)
iframe <- remDr$findElement("css", value=".view-more-less")
option <- remDr$findElement(using = 'xpath', "//*/option[@value = 'view_all']")
option$clickElement()
priceNodes <- remDr$findElements(using = 'css selector', ".price")
price<-unlist(lapply(priceNodes, function(x){x$getElementText()}))
}
私はこのようにそれを適用します。
FPrice("https://www.net-a-porter.com/fr/fr/Shop/Designers/Fendi")
エラーメッセージが上がってきた私は、私が探していますデータを得ることはありません。
Selenium message:stale element reference: element is not attached to the page document
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.33.506106 (8a06c39c4582fbfbab6966dbb1c38a9173bfb1a2),platform=Mac OS X 10.12.6 x86_64)
機能の中に機能があると思います...誰でも問題解決のお手伝いをしていただけますか?ありがとう。
ps。私は別のコードを作った:
Price <- function(x) {
url1 <- x
webpage <- read_html(url1)
price_data_html <- html_nodes(webpage,".price")
price_data <- html_text(price_data_html)
price_data<-gsub("€","",price_data)
price_data<-gsub(",","",price_data)
price_data <- as.numeric(price_data)
return(price_data)
}
そして、うまくいきました。私はadresseのリストを含むベクトルにそれを適用しました。しかし、rvestではブラウザを設定することができないので、 "show all"オプションを選択します。したがって、Fendiの場合のように、私は60の観測値しか得ていないが、いくつかのブランドは200を超える製品を提案している。
ご理解いただきありがとうございます。あなたからすぐに読むことを願っています!