如何使用 Rvest 解决 "xml missing"?
How do I resolve "xml missing" with Rvest?
这是与我感兴趣的节点关联的 XPath:
//*[@id="box-listing"]/div[1]
正在使用
out %>%html_node(xpath = '//*[@id="box-listing"]/div[1]')
出现以下错误
{xml_missing}
<NA>
为了解决你的问题我建议你使用Rselinium
我们有两大网站家族。静态网站和动态网站。
第一个在代码中有我们需要的信息(例如 Wikipidia 网页),而第二个实际上没有代码中的信息,但它每次我们通过 Javascript 代码实现需要它(例如 Trip Advisor)。
感谢 Rselenium
库,我们能够从动态网站上抓取信息。
什么是硒?
RSelenium
是一个 R 库,但我们可以在 Python
、Java
等其他类型的代码中找到它,它能够模拟人类行为。
Selenium
的主要用途是测试应用程序自动化,但并非如此。
Selenium是一个很大的世界(here to deep).
关于 Rselenium 我建议您查看这些链接:
下面是一个关于你的问题的使用 Rselenium 的小例子:
library(RSelenium)
#We start the RSelenium environment
driver <- rsDriver(browser=c("firefox"),port = 4445L)
remote_driver <- driver[["client"]]
#We send the url to the firefox browser
remote_driver$navigate("https://www.immobiliare.it/ricerca-mappa/Torino,TO/#/linkZona_/latitudine_45.04462/longitudine_7.68199/idContratto_1/idCategoria_23/zoom_16/pag_1")
Below some example of the Rselenium powerful
#We get the text
text_1<-remote_driver$findElement(using = "css selector", '#box-listing > div:nth-child(1) > div:nth-child(1)')$getElementText()
print(text_1)
[[1]]
[1] "PREMIUM\nImmobile\n€ 150.000\n60 m² • 2 locali"
#We click the element
remote_driver$findElement(using = "css selector", '#box-listing > div:nth-child(1) > div:nth-child(1)')$clickElement()
这是与我感兴趣的节点关联的 XPath:
//*[@id="box-listing"]/div[1]
正在使用
out %>%html_node(xpath = '//*[@id="box-listing"]/div[1]')
出现以下错误
{xml_missing}
<NA>
为了解决你的问题我建议你使用Rselinium
我们有两大网站家族。静态网站和动态网站。
第一个在代码中有我们需要的信息(例如 Wikipidia 网页),而第二个实际上没有代码中的信息,但它每次我们通过 Javascript 代码实现需要它(例如 Trip Advisor)。
感谢 Rselenium
库,我们能够从动态网站上抓取信息。
什么是硒?
RSelenium
是一个 R 库,但我们可以在 Python
、Java
等其他类型的代码中找到它,它能够模拟人类行为。
Selenium
的主要用途是测试应用程序自动化,但并非如此。
Selenium是一个很大的世界(here to deep).
关于 Rselenium 我建议您查看这些链接:
下面是一个关于你的问题的使用 Rselenium 的小例子:
library(RSelenium)
#We start the RSelenium environment
driver <- rsDriver(browser=c("firefox"),port = 4445L)
remote_driver <- driver[["client"]]
#We send the url to the firefox browser
remote_driver$navigate("https://www.immobiliare.it/ricerca-mappa/Torino,TO/#/linkZona_/latitudine_45.04462/longitudine_7.68199/idContratto_1/idCategoria_23/zoom_16/pag_1")
Below some example of the Rselenium powerful
#We get the text
text_1<-remote_driver$findElement(using = "css selector", '#box-listing > div:nth-child(1) > div:nth-child(1)')$getElementText()
print(text_1)
[[1]]
[1] "PREMIUM\nImmobile\n€ 150.000\n60 m² • 2 locali"
#We click the element
remote_driver$findElement(using = "css selector", '#box-listing > div:nth-child(1) > div:nth-child(1)')$clickElement()