深夜の馬鹿力で出題された問題を解く
TBSラジオの超人気番組,月曜JUNK伊集院光深夜の馬鹿力の「少しおもしろい」のコーナーで気になる投稿があった.
【問題】
都道府県の最初の漢字だけで表すことのできる(多分)唯一の芸能人は長島三奈
(月曜JUNK伊集院光深夜の馬鹿力 20181224深夜放送分より)
伊集院さんも他にないのかなー??と唸っていた.
芸能人のお名前を片っ端から調べてみる.
芸能人のリストとしてgooのタレント一覧のページ(https://news.goo.ne.jp/entertainment/talent)を使う.
残念ながらこちらには,放送内で先に正解例として挙がっている長島三奈さんは含まれていない.他に良さそうな情報源が発見できなかったのでこちらを使用.
目視で調べるのもあれなのでスクレイピングして芸能人の名前リストを取ってくる.
スクレイピングについての参考と注意点は以下.
https://qiita.com/Azunyan1111/items/9b3d16428d2bcc7c9406
https://docs.pyq.jp/column/crawler.html
gooのタレント一覧のページのソースをみると,<p class="list-title-news margin-bottom5">のあとにタレント名が記載されているようなので,
この要素だけ見るようにする.
【https://news.goo.ne.jp/entertainment/talent/j-a/ より】 (中略) <ul class="gn-thumbs-list thumbs-list-large"> <li><a href="/entertainment/talent/W17-0923.html"> <div class="gn-news-item news-list-item"> <div class="news-item-thumbs"><img src="https://img.news.goo.ne.jp/talent/MW-W17-0923.jpg" alt="" class="thumbs-xx-small"></div> </div> <div class="image-news-block"> <p class="list-title-news margin-bottom5">あぁ〜しらき</p> <p class="list-news-source">アァ〜シラキ</p> </div> </a></li> <li><a href="/entertainment/talent/M10-0879.html"> <div class="gn-news-item news-list-item"> <div class="news-item-thumbs"><img src="https://img.news.goo.ne.jp/talent/MM-M10-0879.jpg" alt="" class="thumbs-xx-small"></div> </div> <div class="image-news-block"> <p class="list-title-news margin-bottom5">Asu</p> <p class="list-news-source">アアス</p> </div> (以下略)
https://news.goo.ne.jp/entertainment/talent/j-以下がa-1,a-2,a-3...となっていくので総当たりで調べていく.
ページのソースが回収できたら,先程の<p class="list-title-news margin-bottom5">のあとに続く文字列が,都道府県の最初の漢字だけかを判定.
【name.py】 import urllib.request from bs4 import BeautifulSoup import time #都道府県名最初の一文字と全角スペースのリスト list_todohuken=[" ","北","青","岩","秋","宮","山","福","茨","栃","群","埼","東","長" ,"千","神","静","新","富","石","岐","愛","滋","三","京","奈","和","大","兵","鳥" ,"島","岡","広","香","徳","高","佐","熊","鹿","沖"] #与えられた人名が,すべて都道府県名最初の一文字かを検証する関数 def check_name_todohuken(name): for c in name: if c in list_todohuken: continue else: return #与えられた人名が,すべて都道府県名最初の一文字なら出力 print(name) def check_list_url(url): # html取得 html = urllib.request.urlopen(url) # htmlをBeautifulSoupで扱う soup = BeautifulSoup(html, "html.parser") # p要素全てを摘出する p = soup.find_all("p") # class=""list-title-news margin-bottom5"となっているところを探す for tag in p: try: string_ = tag.get("class").pop(0) if string_ in "list-title-news margin-bottom5": check_name_todohuken(tag.string) except: pass shiin = ["","k","s","t","n","h","m","r"] boin = ["a","i","u","e","o"] other = ["ya","yu","yo","wa"] num = ["1","2","3","4","5"] #子音と母音のセットで各ページをチェック for s in shiin: for b in boin: for n in num: check_list_url("https://news.goo.ne.jp/entertainment/talent/j-"+s+b+"-"+n+"/") #サーバアクセスの間隔を1秒以上空ける time.sleep(1) #「や」「ゆ」「よ」「わ」は個別にチェック for o in other: for n in num: check_list_url("https://news.goo.ne.jp/entertainment/talent/j-"+o+"-"+n+"/") #サーバアクセスの間隔を1秒以上空ける time.sleep(1)
【結果】
秋山 静香
東 千秋
大山 秋
和
神山 大和
静
島 和三
千石 愛
千秋
新奈
新山 大
東 大
大和
大和
和香
和香奈
結構いらっしゃいました.
あまりタレントさんには明るくないので知らない人ばかり.
ああ!確かに!となるのは千秋さん.
データセットを変えれば他にも見つかると思われる.