我正在努力为我正在工作的项目构建一个cik查找函数。我发现了下面的回答
require(XML)
require(RCurl)
getCIK = function(ticker) {
stopifnot(is.character(ticker))
uri = "https://www.sec.gov/cgi-bin/browse-edgar"
response = getForm(uri,CIK=ticker,action="getcompany")
html = htmlParse(response)
CIKNode = getNodeSet(html, "//acronym[@title=\"Central Index Key\"][text() = \"CIK\"]")
CIKNodeText = sapply(CIKNode, function(x) xmlValue(getSibling(getSibling(x))))
CIK = sub(" .*","",CIKNodeText)
CIK = sub("^0*","",CIK)
CIK
}
getCIK("GE")
# "40545"但当我输入getCIK("CLDR")时。我得到了
字符(0)
我想建立我自己的功能:
library(rvest)
ticker = "cldr"
#loc = "New York"
session <- html_session("https://www.sec.gov/edgar/searchedgar/cik.htm")
form <- html_form(session)[[1]]
filled_form <- set_values(form, query = name)
query <- rvest:::submit_request(session, filled_form)我得到了
错误:找不到可能的提交目标。
我试着输入版本的“提交”,但我没有任何运气。有人能给我指点一下吗?
提前感谢!
发布于 2018-04-09 09:00:46
"CLDR“根本不起作用,因为Cloudera的代码在EDGAR系统中没有被更新。当提供其他代码段时,来自第一个代码段的getCIK()很好地工作。
您可以快速地将查询从基于滴答键的查找更改为基于company_name的查找,如下所示
require(XML)
require(RCurl)
getCIKFromCompanyName = function(company_name) {
stopifnot(is.character(company_name))
uri = "https://www.sec.gov/cgi-bin/browse-edgar"
response = getForm(uri,company=company_name,action="getcompany")
html = htmlParse(response)
CIKNode = getNodeSet(html, "//acronym[@title=\"Central Index Key\"][text() = \"CIK\"]")
CIKNodeText = sapply(CIKNode, function(x) xmlValue(getSibling(getSibling(x))))
CIK = sub(" .*","",CIKNodeText)
CIK = sub("^0*","",CIK)
CIK
}
getCIKFromCompanyName("Cloudera")现在,当有一个与您所提供的参数类似的公司名称时,这个方法工作得很好。这在"Google“的情况下失败了,因为其中有多个"Google”的公司名称。
您将不得不诉诸于一些逻辑,您首先使用代码搜索,只有在不起作用的情况下,使用公司名称。
在正确的公司名称方面还有进一步的问题。例如,如果您搜索"Tesla Inc.",则获取失败。你必须搜索“特斯拉汽车”,因为这是公司的原始名称。
希望这能有所帮助。
https://stackoverflow.com/questions/49727566
复制相似问题