首页 > 解决方案 > 使用 R 抓取 JavaScript 繁重的网页

问题描述

我希望使用 Rvest 和 V8 在 R 中抓取公开可用的地块描述。但是,我很难通过页面上的 JavaScript,因为它是高度动态的。这是我到目前为止的代码:

GISurl <- "https://hosting.tighebond.com/plainfieldct_public/##info-address"

GIS <- read_html(GISurl)

owners <- GIS %>% html_nodes("div.owner") %>% html_text()

# Create a new v8 context
ct <- v8()

#parse the html content from the js output and print it as text
read_html(ct$eval(gsub('document.write','', owners))) %>% html_text()

我不断收到一条错误消息,内容如下:

context_eval(join(src), private$context, serialize) 中的错误:ReferenceError: parcel 未定义。

据我了解,该消息正在弹出,因为 R 不知道我想要来自哪块土地的数据。我将如何从所有包裹(而不是特定的预定包裹)中提取数据?

标签: javascriptrweb-scrapingv8rvest

解决方案


推荐阅读