[問題] 魚類資料庫爬蟲,爬不出來

作者: mary84215 (過剩芒果蘇)   2018-10-23 23:30:50
[問題類型]:
程式諮詢(我想用R 做某件事情,但是我不知道要怎麼用R 寫出來)
[軟體熟悉度]:
使用者(已經有用R 做過不少作品)
[問題敘述]:
各位大大好,我想在FishBase網站把這種魚的Human uses爬下来,網址如下方所列
http://www.fishbase.org/summary/Decapterus-maruadsi.html
以此網頁為例,我使用套件rvest爬蟲,並配合SelectorGadget取得元素的css路徑或是xp
ath
原本期待能爬出"Fisheries: highly commercial",但是不知爲何總是爬出character(0)
已經試過許多方法,且此網頁應該也不是動態網頁,但還是不得其解QQ
只好來這裡求助各位大大了,謝謝各位
[程式範例]:
rm(list=ls())
library("rvest")
library("xml2")
library("magrittr")
library("httr")
page=read_html("http://www.fishbase.org/summary/Decapterus-maruadsi.html")
page %>% html_nodes(".smallSpace:nth-child(44) span") %>%
html_text()
[環境敘述]:
R version 3.3.1 (2016-06-21)
Platform: x86_64-apple-darwin13.4.0 (64-bit)
Running under: OS X 10.12.6 (Sierra)
locale:
[1] zh_TW.UTF-8/zh_TW.UTF-8/zh_TW.UTF-8/C/zh_TW.UTF-8/zh_TW.UTF-8
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] httr_1.3.1 magrittr_1.5 rvest_0.3.2 xml2_0.1.2
loaded via a namespace (and not attached):
[1] selectr_0.4-1 R6_2.1.2 tools_3.3.1 curl_3.1 Rcpp_0.12.4
[6] stringi_1.0-1 stringr_1.0.0
[關鍵字]:
爬蟲、rvest
作者: TreeMan (好啊...)   2018-10-24 08:09:00
html_nodes內改成Chrome插件XPath Helper找到的path可以n")html_nodes(xpath = "//div[@class='smallSpace'][9]/span")
作者: mary84215 (過剩芒果蘇)   2018-10-24 23:54:00
謝謝你!這樣就成功了!

Links booklink

Contact Us: admin [ a t ] ucptt.com