今日書いたのはこれ。 日経225の構成銘柄が変更になるといちいち変更が面倒なので作りました。 コメントに書いてある機能しかありませんが、簡単でよし。 ご参考になれば。 #!/usr/local/bin/python # -*- coding:utf-8 -*- from BeautifulSoup import BeautifulSoup import urllib2,re class Nikkei225Profile(object): def __init__(self): ''' 日経新聞のサイトから日経225の構成銘柄の証券コードと証券名称を取得 ''' self.url = 'http://www3.nikkei.co.jp/nkave/about/225_list.cfm' self.profile = dict() soup = BeautifulSoup(urllib2.urlopen(self.url)) tablesoup = soup.find("table") rows = tablesoup.findAll('tr',{'bgcolor':'#FFF5DE'}) rows += tablesoup.findAll('tr',{'bgcolor':'#F0E7D1'}) for row in rows: row_list = [cell.find(text=True) for cell in row.findAll('td')] self.profile[row_list[0]] = row_list[1] def getprofile(self,googlestyle=False): ''' 日経225の証券コードと証券名称をdict()で返す ...
コメント
コメントを投稿