从Yahoo.Infinance的行业获得股票代号清单的财务信息 [英] Getting industry from Yahoo.Finance for list of stock ticker

查看:61
本文介绍了从Yahoo.Infinance的行业获得股票代号清单的财务信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我如何(最好使用R)如何从Yahoo.Finance,Google Finance或其他工具获取股票行情清单的行业分类.为了说明这一点,我列出了一些行情自动收录器,例如

How can I (preferably using R) get the industry classification for a list of stock tickers from Yahoo.Finance, Google Finance or anything else. To illustrate, I have a list of tickers, such as

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为每个股票获得相应的行业.

Preferably, R fetches the corresponding industry for each ticker.

推荐答案

此功能应为您完成工作...

This function should do the work for you...

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,'&amp;','&')
  return(ind)
}

这篇关于从Yahoo.Infinance的行业获得股票代号清单的财务信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆