问题描述
我希望抓取一个使用标签的网页。我对rvest
运气不太好,所以我正在尝试splashR
。
Splash是专门设计用于Web抓取的无头浏览器 。如本introduction中所述,您将需要访问Splash环境。我建议按照介绍中所述使用Docker容器。我以前从未使用过Docker,但是在这种情况下,设置起来很简单。
与此:
library(HARtools)
library(splashr)
library(tidyverse)
td_raw <- possibly(render_har,"bad")(url = "https://www.td.com/ca/en/personal-banking/products/saving-investing/gic-rates-canada/",wait = 5,response_body = TRUE)
har_entries(td_raw) %>%
purrr::map_chr(get_content_type) %>%
table(dnn = "content_type") %>%
broom::tidy() %>%
dplyr::arrange(desc(n))
# A tibble: 11 x 2
content_type n
<chr> <int>
1 image/gif 118
2 application/javascript 69
3 text/javascript 48
4 text/html 26
5 image/png 10
6 application/font-woff2 6
7 application/json 5
8 application/x-javascript 4
9 text/css 4
10 image/svg+xml 3
11 text/plain 1
根据您的计算方式,页面上有5个表格。因此,看看application/json
中的内容是一个开始。
har_entries(td_raw) %>%
purrr::keep(is_json) %>%
purrr::map(get_response_body,"text") %>%
purrr::map(jsonlite::fromJSON)
Error: lexical error: invalid char in json text.
EGAINCLOUD._callback.eg3c465e5d
(right here) ------^
如何以“更友好的”数据框格式获取费率信息?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)