【问题标题】:Scraping 13F filings from SEC using R使用 R 从 SEC 抓取 13F 文件
【发布时间】:2021-07-02 15:17:51
【问题描述】:

我正在尝试从以下链接中抓取 SEC FORM 13-F 信息表中的数据:

https://sec.report/Document/0001567619-21-010281/

我尝试了以下脚本:

library(timetk)
library(tidyverse)
library(rvest)
url <- "https://sec.report/Document/0001567619-21-010281/"
url <- read_html(url)
raw_data <- url %>%
  html_nodes("#table td") %>%
  html_text()

但是,我无法获取数据组件,并且在值下,它说raw_data 是空的。任何帮助将不胜感激。

【问题讨论】:

  • 查看 fmpcloudr 包。

标签: r web-scraping sec


【解决方案1】:

数据存在于响应中。您可以使用 CSS attribute = value 选择器来定位嵌套表。您将需要决定最有可能(或不!)需要转换为单个标题的前三行决定什么

library(rvest)
library(magrittr)

page <- read_html("https://sec.report/Document/0001567619-21-010281/")

table <- page %>%
  html_node('[summary="Form 13F-NT Header Information"]') %>%
  html_table(fill = T)

【讨论】:

    【解决方案2】:

    使用 html 页面中的 13F 更容易这里是一个例子

    import pandas as pd
    import requests
    import numpy as np
    
    
    # Makes a request to the url
    url="https://www.sec.gov/Archives/edgar/data/1541617/000154161721000009/xslForm13F_X01/altcap13f3q21infotable.xml"
    request = requests.get(url, headers={"User-Agent": "Mozilla/5.0"})
    
    # Pass the html response into read_html
    tables = pd.read_html(request.text)
    df = tables[3] 
    

    【讨论】:

    • 原题中使用的语言是R。这个答案是用python写的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-01-18
    • 2016-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多