1
我正在處理和玩「rvest」。用「read_html」獲取數據是可以的。webscraping:手動更換標籤
library(rvest)
# suppressMessages(library(dplyr))
library(stringr)
library(XML)
# get house data
houseurl <- "http://boekhoff.de/immobilien/gepflegtes-zweifamilienhaus-in-ellwuerden/"
house <- read_html(houseurl)
house
我在處理數據時遇到了一些問題。來源評論我的問題。
## eleminating <br>-tags in address
# using the following commands causes error using "html_nodes"
str_extract_all(house,"<br>") ## show all linebreaks
# replacing <br> in whitespace " ",
house <- str_replace_all(house,"<br>", " ")
現在讀出細節,但似乎不起作用
houseattribut <- house %>%
html_nodes(css = "div.col-2 li p.data-left") %>%
html_text(trim=TRUE)
# shows "Error in UseMethod("xml_find_all") : ... "
# but all attributes are shown on screen
houseattribut
沒有更換「BR」標籤都有效手動其工作,但「HTML_TEXT」收緊串在一起
housedetails <- house %>%
html_nodes(css = "div.col-2 li p.data-right") %>%
html_text()
housedetails
# the same error shows "Error in UseMethod("xml_find_all") : ... "
# but all details are shown on screen
housedetails[4]
# in the source there is: "Ellwürder Straße 17<br>26954 Nordenham"
# at <br>-tag should be a whitespace
任何提示我做錯了什麼?
謝謝你,這就是我要找的。 – wattnwurm