将棋プロ棋士のプロフィールを拾ってくるクラス
日本将棋連盟のサイトから棋士のプロフィールを拾ってくる。 作ってみたは良いけど、使いみちは特にないw
kp = KishiPicker('https://www.shogi.or.jp/player/pro/175.html') ret = kp.parson_name() print(ret) # ('羽生善治', 'Yoshiharu Habu') ret = kp.profile_all() print(ret) # [('棋士番号', '175'), ('生年月日', '1970年9月27日(48歳)'), ('出身地', '埼玉県所沢市'), ('師匠', '(故)二上達也九段'), ('竜王戦', '1組(1組以上:28期)'), ('順位戦', 'A級(A級以上:26期)')] ret = kp.victory_history() print(ret) # [('朝日杯将棋オープン戦', '5回(第3回-2009年度・5回・7回・8回・9回)'), ('朝日オープン選手権', '4回(第22回-2003年度~25回-2006年度)'), ('全日本プロトーナメント', '3回(第8回-1989年度・10回・16回)'), ('銀河戦', '5回(第8回-1999年度・第8回・9回・第12回・第14回・第20回※非公式戦時代の第5・6回も)'), ('NHK杯戦', '11回(第38回-1988年度・41回・45回・47回・48回・50回・58回~61回・68回) -名誉NHK杯選手権者'), ('早指し選手権戦', '3回(第26回-1992年度・29回・36回)'), ('将棋日本シリーズ\u3000JTプロ公式戦', '5回(第12回-1991年度・19回・24回・31・32回)'), ('新人王戦', '1回(第19回-1988年度)'), ('勝抜戦5勝以上', '4回(第11回-1988年度・13回・20回・22回)'), ('天王戦', '2回(第3回-1987年度・4回)'), ('若獅子戦', '2回(第10回-1987年度・12回)')]
#!/usr/bin/env python # coding: utf-8 from bs4 import BeautifulSoup import requests import json class KishiPicker: def __init__(self, url): self.url = url self.soup = self._fetchKishiDB() def _fetchKishiDB(self): req = requests.get(self.url) soup = BeautifulSoup(req.content, 'lxml') return soup def parson_name(self): # 棋士の名前 en = self.soup.select('div .section04 .nameArea .en')[0].text return self.soup.select('div .section04 .nameArea .jp')[0].text, en def parson_rank(self): # 段位 return self.soup.select('div .section04 .headingElementsA01')[0].text, def profile_all(self): # 棋士番号、生年月日、出身地、師匠、竜王戦、順位戦 sec04_th = self.soup.select('div .section04 .innerBlock01 th') sec04_td = self.soup.select('div .section04 .innerBlock01 td') return [x for x in zip([th.text for th in sec04_th], [td.text for td in sec04_td])] def last_year_result(self): # 前年度対戦履歴 _th = [x.text.strip() for x in self.soup.select('h3 + .section04 .tableElements02 th')] _td = [x.text.strip() for x in self.soup.select('h3 + .section04 .tableElements02 td')] last_year_result = [last_year for last_year in zip(_th, _td)] return last_year_result def match_result(self): # 今季対戦履歴 _temp = [] _matchresult = [x.text.strip() for x in self.soup.select('.sp_player_matchresult .tableElements02 td')] matchresult = [] for i in range(0, len(_matchresult), 4): for j in range(4): _temp.append(_matchresult[i+j]) else: matchresult.append(_temp) _temp = [] #初期化 return matchresult def title_history(self): # タイトル履歴 _th = [th.text for th in self.soup.select('.section02 #anc01 .tableElements02 th')] _td = [td.text for td in self.soup.select('.section02 #anc01 .tableElements02 td')] title_history = [_title for _title in zip(_th, _td)] return title_history def victory_history(self): # 優勝履歴 _th = [th.text for th in self.soup.select('.section02 #anc02 .tableElements02 th')] _td = [td.text for td in self.soup.select('.section02 #anc02 .tableElements02 td')] victory_history = [_victory for _victory in zip(_th, _td)] return victory_history def taisho_history(self): # 将棋大賞 _th = [th.text for th in self.soup.select('.section03 .tableElements02 th')] _td = [td.text for td in self.soup.select('.section03 .tableElements02 td')] taisho_history = [_taisho for _taisho in zip(_th, _td)] return taisho_history def other_history(self): # その他表彰 _th = [th.text for th in self.soup.select('.section01 h3 + .tableElements02 th')] _td = [td.text for td in self.soup.select('.section01 h3 + .tableElements02 td')] other_history = [other for other in zip(_th, _td)] return other_history
- 作者: 羽生善治
- 出版社/メーカー: 角川書店
- 発売日: 2005/07/08
- メディア: 新書
- 購入: 44人 クリック: 297回
- この商品を含むブログ (562件) を見る
- 作者: 羽生善治,梅原猛,尾本恵市
- 出版社/メーカー: 講談社
- 発売日: 2019/05/15
- メディア: 新書
- この商品を含むブログを見る
- 作者: 羽生善治
- 出版社/メーカー: KADOKAWA / 角川書店
- 発売日: 2014/01/20
- メディア: Kindle版
- この商品を含むブログを見る