LoginSignup
0
0

More than 5 years have passed since last update.

PythonでNPBのチームデータが取りたい。(選手情報取る。荒削り)

Posted at

wikipediaからざっくりと選手の名前を取得する。
選手名以外も取れちゃってるからもう少し加工したい。

get_player.py
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import bs4
import requests

url = requests.get('https://ja.wikipedia.org/wiki/%E5%8D%83%E8%91%89%E3%83%AD%E3%83%83%E3%83%86%E3%83%9E%E3%83%AA%E3%83%BC%E3%83%B3%E3%82%BA%E3%81%AE%E9%81%B8%E6%89%8B%E4%B8%80%E8%A6%A7')
url.raise_for_status()
if (url.status_code == 200):#htmlのステータスを確認して正常なら実行
    soup = bs4.BeautifulSoup(url.text,'html.parser')
    elems = soup.select('a')
    for elem in elems:
        print(elem.string)
else:#errorだったときにURLが取れてなかったエラーがでる。
    print("URL error!")
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0