【发布时间】:2020-08-21 11:27:36
【问题描述】:
我在这里存储了 xml 文件。它包含 json。我无法读取并将其转换为数据框
清理代码
htext <- html_nodes(content, xpath=".//script[contains(., 'home_js_model')]") %>% html_text()
htext <- gsub("<script type=\"text/javascript\">", "", htext, fixed=TRUE)
htext <- gsub("var home_js_model = {", "", htext, fixed=TRUE)
htext <- gsub("</script>", "", htext, fixed=TRUE)
htext <- gsub("stock\":", "", htext, fixed=TRUE)
从 JSON 读取
json <- jsonlite::fromJSON(htext)
我也尝试过,但没有成功。
jsonlite::stream_in(textConnection(gsub("\\n", "", htext)))
【问题讨论】:
-
“没有成功”是什么意思?你有任何错误吗?
json是空的还是NULL?htext的值是多少?