選手会のHPからソースを参照してaタグの部分を抜き出し
hrefのところから該当のpathを特定
ファイル名をチーム名.pdfでDLする。
getPDF_DL.py
import bs4
import requests
import urllib3
url = requests.get('http://jpbpa.net/register/')
url.raise_for_status()
# HTMLparserでHTMLのaタグだけ絞り込み
soup = bs4.BeautifulSoup(url.text, "html.parser")
elems = soup.select('a')
for elem in elems:
team = elem.getText()
path = elem.get('href')
repath = path.replace('..', 'http://jpbpa.net')
# elem.getText=球団名、elem.get('href')=PDFのpath
if elem.getText() in {'ロッテ', 'ソフトバンク', '西武', '楽天', 'オリックス', '日本ハム',
'広島', '阪神', 'DeNA', '巨人', '中日', 'ヤクルト'}:
#print('{}({})'.format(team, repath))
# pdfのDLチーム名.pdfにする。
request_methods = urllib3.PoolManager()
response = request_methods.request('GET', repath)
f = open(team + '.pdf', 'wb')
f.write(response.data)
f.close()