{"id":1017,"date":"2017-08-04T01:35:42","date_gmt":"2017-08-03T16:35:42","guid":{"rendered":"https:\/\/www.dogrow.net\/python\/?p=1017"},"modified":"2018-09-18T05:48:38","modified_gmt":"2018-09-17T20:48:38","slug":"blog86","status":"publish","type":"post","link":"https:\/\/www.dogrow.net\/python\/blog86\/","title":{"rendered":"(86) NPB\u30d7\u30ed\u91ce\u7403\u9078\u624b\u306e\u5e74\u5225\u6210\u7e3e\u3092\u53d6\u5f97\u3059\u308b\u3002"},"content":{"rendered":"<p>NPB\u69d8\u306e\u30b5\u30a4\u30c8\u306b\u306f\u3001\u73fe\u5f79\u5168\u9078\u624b\u306e\u5e74\u5225\u6210\u7e3e\u304c\u63b2\u8f09\u3055\u308c\u3066\u3044\u308b\u3002<br \/>\n\u8da3\u5473\u3067\u3044\u308d\u3044\u308d\u3068\u7d71\u8a08\u8a08\u7b97\u3092\u3057\u3066\u307f\u305f\u3044\u306e\u3060\u304c\u3001\u9078\u624b\u500b\u3005\u306e\u30c7\u30fc\u30bf\u3092\u30b3\u30d4\u30da\u3067Excel\u306b\u8cbc\u308a\u4ed8\u3051\u308b\u4f5c\u696d\u306b\u306f\u9650\u754c\u304c\u3042\u308b\u3002<br \/>\n\u305d\u3053\u3067\u3001\u307e\u305f\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3067\u53d6\u5f97\u3059\u308b\u3053\u3068\u306b\u3059\u308b\u3002<\/p>\n<p>\u4ee5\u524d <a href=\"https:\/\/www.dogrow.net\/python\/?p=730\">(81) \u91ce\u7403\u9078\u624b\u306e\u6210\u7e3e\u3092\u4e3b\u6210\u5206\u5206\u6790 (\u7d9a\u7de81\/2)<\/a> \u3067\u306fYahoo\u30b9\u30dd\u30fc\u30c4\u69d8\u306e\u30b5\u30a4\u30c8\u306e\u63b2\u8f09\u60c5\u5831\u3092\u8a08\u7b97\u306b\u4f7f\u308f\u305b\u3066\u3044\u305f\u3060\u3044\u305f\u3002\u4eca\u56de\u306fNPB\u69d8\u306e\u30c7\u30fc\u30bf\u3092\u53d6\u5f97\u3057\u3066\u307f\u305f\u3044\u3002<\/p>\n<p>\u8a66\u4f5c\u3057\u305f\u30d7\u30ed\u30b0\u30e9\u30e0\u3067\u306f\u3001\u73fe\u5728\u4e09\u51a0\u738b\u306e\u67f3\u7530\u9078\u624b\u306e\u30da\u30fc\u30b8\u3092\u5bfe\u8c61\u306b\u30c7\u30fc\u30bf\u53d6\u5f97\u3057\u3066\u307f\u308b\u3002<br \/>\n<a href=\"http:\/\/npb.jp\/bis\/players\/31835133.html\" target=_blank><img decoding=\"async\" src=\"https:\/\/www.dogrow.net\/python\/wp-content\/uploads\/2017\/08\/Image1.png\" alt=\"\" class=\"my_img\" \/><\/a><\/p>\n<p>\u5b9f\u884c\u7d50\u679c\u306f\u3053\u3093\u306a\u611f\u3058\u306b\u306a\u3063\u305f\u3002<br \/>\nCSV\u30d5\u30a1\u30a4\u30eb\u306a\u306e\u3067\u3001\u3053\u306e\u5f8c\u306f\u3044\u308d\u3044\u308d\u306a\u30c4\u30fc\u30eb\u3067\u8aad\u307f\u8fbc\u3093\u3067\u8a08\u7b97\u306b\u4f7f\u3048\u308b\u3002<\/p>\n<pre>\r\n2011,\u798f\u5ca1\u30bd\u30d5\u30c8\u30d0\u30f3\u30af,6,5,5,1,0,0,0,0,0,0,0, 0,0, 0,0,0,3, 0,.000,.000,.000\r\n2012,\u798f\u5ca1\u30bd\u30d5\u30c8\u30d0\u30f3\u30af,68,212,195,17,48,10,1,5,75,18,6, 1,2, 0,10,5,56, 2,.246,.385,.300\r\n2013,\u798f\u5ca1\u30bd\u30d5\u30c8\u30d0\u30f3\u30af,104,337,298,48,88,19,2,11,144,41,10, 1,0, 0,32,7,96, 3,.295,.483,.377\r\n2014,\u798f\u5ca1\u30bd\u30d5\u30c8\u30d0\u30f3\u30af,144,615,524,91,166,18,4,15,237,70,33, 6,0, 3,72,16,131, 8,.317,.452,.413\r\n2015,\u798f\u5ca1\u30bd\u30d5\u30c8\u30d0\u30f3\u30af,138,605,502,110,182,31,1,34,317,99,32, 8,0, 1,88,14,101, 9,.363,.631,.469\r\n2016,\u798f\u5ca1\u30bd\u30d5\u30c8\u30d0\u30f3\u30af,120,536,428,82,131,31,4,18,224,73,23, 2,0, 0,100,8,97, 8,.306,.523,.446\r\n2017,\u798f\u5ca1\u30bd\u30d5\u30c8\u30d0\u30f3\u30af,93,400,317,73,105,23,0,25,203,80,14, 7,0, 7,70,6,86, 5,.331,.640,.453\r\n<\/pre>\n<h1 class=my_h1 style=\"margin-top:2rem\">\u25a0\u4ed5\u69d8<\/h1>\n<p>\u30fb\u9078\u624b\u7d39\u4ecb\u30da\u30fc\u30b8\u306eURL\u3092\u4e0e\u3048\u308b\u3002<br \/>\n\u30fb\u5bfe\u8c61\u30da\u30fc\u30b8\u304b\u3089\u5e74\u5225\u6210\u7e3e\u3092\u62bd\u51fa\u3057\u3066CSV\u30d5\u30a1\u30a4\u30eb\u306b\u4fdd\u5b58\u3059\u308b\u3002<\/p>\n<h1 class=my_h1 style=\"margin-top:2rem\">\u25a0\u30d7\u30ed\u30b0\u30e9\u30e0<\/h1>\n<h3 class=my_h3>\u30b3\u30de\u30f3\u30c9\u30e9\u30a4\u30f3\u5165\u529b<\/h3>\n<pre>\r\n$ python3\r\n\r\n>>> import lib_npb\r\n>>> cPlayer = lib_npb.get_player_data(\"http:\/\/npb.jp\/bis\/players\/31835133.html\")\r\n>>> cPlayer.output_record_to_csv_file(\"data.txt\")\r\n<\/pre>\n<h3 class=my_h3>lib_npb.py<\/h3>\n<pre class=\"brush: python; title: ; notranslate\" title=\"\">\r\nimport urllib.request\r\nfrom bs4 import BeautifulSoup\r\nimport csv\r\n\r\n#\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\nclass NpbPlayer:\r\n    def __init__(self, name):\r\n        self.name = name\r\n        self.ary_record = &#x5B;]\r\n\r\n    def append_record(self, ary):\r\n        self.ary_record.append(ary)\r\n\r\n    def output_record_to_csv_file(self, fname):\r\n        with open(fname, &quot;w&quot;) as fh:\r\n            writer = csv.writer(fh, lineterminator=&quot;\\n&quot;)\r\n            writer.writerows(self.ary_record)\r\n\r\n#\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\ndef get_player_data_detail( resp ):\r\n    bs = BeautifulSoup(resp.read(), &quot;html.parser&quot;)\r\n    # find name\r\n    td = bs.find(&quot;td&quot;,{&quot;class&quot;:&quot;registerPlayer&quot;})\r\n    h1 = td.find(&quot;h1&quot;)\r\n    cPlayer = NpbPlayer(h1.get_text())\r\n    # find record\r\n    div = bs.find(&quot;div&quot;,{&quot;id&quot;:&quot;registermaintbl&quot;})\r\n    for tr in div.findAll(&quot;tr&quot;,{&quot;class&quot;:&quot;registerStats&quot;}):\r\n        ary_1_record = &#x5B;]\r\n        for td in tr.findAll(&quot;td&quot;):\r\n            ary_1_record.append(td.get_text())\r\n        cPlayer.append_record(ary_1_record)\r\n    return cPlayer\r\n\r\n#\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\r\ndef get_player_data( url ):\r\n    try:\r\n        resp = urllib.request.urlopen(url)\r\n    except urllib.error.HTTPError as e:\r\n        print(&quot;HTTP-Error : &quot;, e.code)\r\n        return None\r\n    except urllib.error.URLError as e:\r\n        print(&quot;URL-Error : &quot;, e.reason)\r\n        return None\r\n    else:\r\n        cPlayer = get_player_data_detail(resp)\r\n        return cPlayer\r\n<\/pre>\n<hr class=\"my_hr_bottom\">\n","protected":false},"excerpt":{"rendered":"<p>NPB\u69d8\u306e\u30b5\u30a4\u30c8\u306b\u306f\u3001\u73fe\u5f79\u5168\u9078\u624b\u306e\u5e74\u5225\u6210\u7e3e\u304c\u63b2\u8f09\u3055\u308c\u3066\u3044\u308b\u3002 \u8da3\u5473\u3067\u3044\u308d\u3044\u308d\u3068\u7d71\u8a08\u8a08\u7b97\u3092\u3057\u3066\u307f\u305f\u3044\u306e\u3060\u304c\u3001\u9078\u624b\u500b\u3005\u306e\u30c7\u30fc\u30bf\u3092\u30b3\u30d4\u30da\u3067Excel\u306b\u8cbc\u308a\u4ed8\u3051\u308b\u4f5c\u696d\u306b\u306f\u9650\u754c\u304c\u3042\u308b\u3002 \u305d\u3053\u3067\u3001\u307e\u305f\u30b9\u30af\u30ec\u30a4\u30d4\u30f3\u30b0\u3067\u53d6\u5f97\u3059\u308b\u3053\u3068\u306b\u3059\u2026 <span class=\"read-more\"><a href=\"https:\/\/www.dogrow.net\/python\/blog86\/\">\u7d9a\u304d\u3092\u8aad\u3080 &raquo;<\/a><\/span><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[30],"tags":[],"class_list":["post-1017","post","type-post","status-publish","format-standard","hentry","category-beautifulsoup"],"views":4376,"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/1017","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/comments?post=1017"}],"version-history":[{"count":17,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/1017\/revisions"}],"predecessor-version":[{"id":1889,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/posts\/1017\/revisions\/1889"}],"wp:attachment":[{"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/media?parent=1017"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/categories?post=1017"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.dogrow.net\/python\/wp-json\/wp\/v2\/tags?post=1017"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}