【问题标题】:Is there a way to download a CSV file from "website button click" without using RSelenium in R?有没有办法在不使用 R 中的 RSelenium 的情况下从“网站按钮单击”下载 CSV 文件?
【发布时间】:2021-08-01 23:14:09
【问题描述】:

链接是: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")

【问题讨论】:

  • Zwirtes,欢迎来到 SO!你能多说一点……你为什么提到RSelenium?看起来您可以从 base R 中获取带有 utils::download.file() 的文件,不是这样吗?

标签: html r web-scraping data-import


【解决方案1】:

“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 中快速抓取和抓取项目

【讨论】:

    猜你喜欢
    • 2019-09-18
    • 2020-09-12
    • 1970-01-01
    • 1970-01-01
    • 2015-06-22
    • 1970-01-01
    • 2021-11-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多