前提・実現したいこと
webスクレイピングで、サッカーのクラブチームの情報をまとめたいです。
https://www.jleague.jp/
発生している問題・エラーメッセージ
IndexError: list index out of range
該当のソースコード
python
1import csv 2from urllib.request import urlopen 3from bs4 import BeautifulSoup 4 5#URLの指定 6html = urlopen("https://www.jleague.jp/sp/club/sapporo/day/#player") 7bsObj = BeautifulSoup(html, "html.parser") 8 9#テーブルを指定 10table = bsObj.findAll("table",{"class":"playerDataTable"})[0] 11rows = table.findAll("tr") 12 13csvFile = open("player.csv", 'wt', newline = '', encoding = 'utf-8') 14writer = csv.writer(csvFile) 15 16try: 17 for row in rows: 18 csvRow = [] 19 for cell in row.findAll(['td', 'th']): 20 csvRow.append(cell.get_text()) 21 writer.writerow(csvRow) 22finally: 23 csvFile.close()
試したこと
utfを変えてみた
if文を追加した
補足情報(FW/ツールのバージョンなど)
使ったサイト
https://www.jleague.jp/sp/club/sapporo/day/#player
Python 3.6.4 :: Anaconda, Inc.
で、しつもんはなんでしょうか
返信ありがとうございます。 https://www.jleague.jp/sp/club/sapporo/day/#playerの ページにあるプレイヤーリストをエラーなく、csvファイルにして出力したいです
回答1件
あなたの回答
tips
プレビュー