我怎样才能从这个网站得到 href attr?

How can I get href attr from this website?

我正在尝试解析此 web site 的 html,当我从假定的链接中获取 html_nodes 时,它会为所有节点获取响应“”。我做错了什么?

texto_01 <- read_html(URL)
titulos_noticias <- texto_01 %>% html_nodes("p") %>% html_nodes("div") %>% html_nodes("ol") %>% html_nodes("li")  %>% html_nodes("a")
titulos_noticias_texto <- html_attr(titulos_noticias,"href")
titulos_noticias_texto

感谢您的帮助。非常感谢,费利佩

内容是动态加载的。您可以看到页面进行搜索,然后返回结果集。您需要模仿您可以在网络选项卡中找到的实际搜索请求。返回的结果采用 json 格式。感兴趣的数据在 r$Rows 内,您通过连接部分构造 url:

paste0("https://www.bcb.gov.br/estabilidadefinanceira/exibenormativo?tipo=", item$TipodoNormativoOWSCHCS,'&numero=',as.integer(item$NumeroOWSNMBR))

您可以使用 paste0map_df 在从 r$Rows.[=19 返回的 json 对象的循环中处理此 url 重建=]

您可以在源选项卡中找到的 js 文件 https://www.bcb.gov.br/BcbModule.cdb75dd11ebbc7b56192.js 的第 6816 行看到 javascript 处理这个过程。

请注意,js 使用的是第 5609 行中已设置的变量


回复:

library(jsonlite)
library(purrr)

r = jsonlite::read_json('https://www.bcb.gov.br/api/search/app/normativos/buscanormativos?querytext=ContentType:normativo AND contentSource:normativos AND cessão&rowlimit=15&startrow=0&sortlist=Data1OWSDATE:descending&refinementfilters=Data:range(datetime(2018-09-17),datetime(2019-09-20T23:59:59))')

df <- map_df(r$Rows, function(item) {
  data.frame(title = item$title,
             url = paste0("https://www.bcb.gov.br/estabilidadefinanceira/exibenormativo?tipo=", item$TipodoNormativoOWSCHCS,'&numero=',as.integer(item$NumeroOWSNMBR)),
             stringsAsFactors=FALSE)
})

head(df)