首页 > 解决方案 > 有没有办法在不使用 R 中的 RSelenium 的情况下从“网站按钮单击”下载 CSV 文件?

问题描述

链接是:http ://www.b3.com.br/pt_br/produtos-e-servicos/negociacao/renda-variavel/fundos-de-investimentos/fii/fiis-listados/

我必须单击“Exportar lista completa de Fundos em CSV”按钮来下载文件

出于某种原因,我可以在 R 中阅读页面的唯一方法是使用

url = "http://www.b3.com.br/pt_br/produtos-e-servicos/negociacao/renda-variavel/fundos-de-investimentos/fii/fiis-listados/"
download.file(url1, destfile = "scrapedpage.html", quiet=TRUE)

content <- read_html("scrapedpage.html")

标签: htmlrweb-scrapingdata-import

解决方案


“Exportar lista completa de Fundos em CSV”按钮来自不同的来源,如果您在 chrome 上打开开发工具,您可以看到整个主体位于 iframe 中,其来源是https://sistemaswebb3-listados.b3。 com.br/fundsPage/7

我建议你

  1. 先获取 iframe 源,然后
  2. 刮它以找到btn的链接。

对于这种情况,它是https://sistemaswebb3-listados.b3.com.br/fundsProxy/fundsCall/GetListFundDownload/eyJ0eXBlRnVuZCI6NywicGFnZU51bWJlciI6MSwicGFnZVNpemUiOjIwfQ== 这将 csv 数据您所要做的就是将其转换为 csv。

由于您可以轻松地从网站源代码中获取这些内容,因此您可以使用cheerio从 HTML 中快速抓取和抓取项目


推荐阅读