LoginSignup
0
1

More than 5 years have passed since last update.

PythonでNPBのチームデータが取りたい。(選手情報取りたいけど・・・)

Last updated at Posted at 2018-06-20

選手の情報を引っこ抜きたいけど失敗した例。

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

rq = 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')
if (rq.status_code == 200):#htmlのステータスを確認して正常なら実行
    # print(rq.text)
    soup = bs4.BeautifulSoup(rq.text,'html.parser')
    for news in soup.findAll('li'):
        print(news.string)
else:#errorだったときにURLが取れてなかったエラーがでる。
    print("URL error!")
0
1
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
1