从 Yahoo.Finance 获取股票代码列表的行业
Getting industry from Yahoo.Finance for list of stock ticker
我如何(最好使用 R)从 Yahoo.Finance、Google 金融或其他任何地方获取股票行情列表的行业分类。
为了说明,我有一个代码列表,例如
ticker_industy <- data.frame(ticker=ticker_list,industry=rep(NA,length(ticker_list)
head(ticker_industry)
ticker industry
1 BDX NA
2 BLL NA
3 CB NA
4 CELG NA
5 CHK NA
6 CI NA
最好,R 为每个代码获取相应的行业。
这个函数应该可以为您完成工作...
industry=function(ticker)
{
url=paste("https://in.finance.yahoo.com/q/in?s=",ticker,sep=',')
mydata=as.data.frame(readLines(url))
names(mydata)="text"
ind=str_match(as.character(mydata$text[117]),'(?:<b>Industry: ?)(.*?)(?:<)')[,2]
ind=str_replace_all(ind,'&','&')
return(ind)
}
我如何(最好使用 R)从 Yahoo.Finance、Google 金融或其他任何地方获取股票行情列表的行业分类。 为了说明,我有一个代码列表,例如
ticker_industy <- data.frame(ticker=ticker_list,industry=rep(NA,length(ticker_list)
head(ticker_industry)
ticker industry
1 BDX NA
2 BLL NA
3 CB NA
4 CELG NA
5 CHK NA
6 CI NA
最好,R 为每个代码获取相应的行业。
这个函数应该可以为您完成工作...
industry=function(ticker)
{
url=paste("https://in.finance.yahoo.com/q/in?s=",ticker,sep=',')
mydata=as.data.frame(readLines(url))
names(mydata)="text"
ind=str_match(as.character(mydata$text[117]),'(?:<b>Industry: ?)(.*?)(?:<)')[,2]
ind=str_replace_all(ind,'&','&')
return(ind)
}