pythonでJRAの「過去レース結果検索」のアドレスを作る
JRAの「過去レース結果検索」は年月を入力するページなのですが
面倒なのでアドレスを探ってみた、ページのソースをみると
アドレスは('/JRADB/accessS.html','pw01skl10202301/チェックデジット)
又は('/JRADB/accessS.html','pw01skl00202301/チェックデジット)らしい
チェックデジットはobjParamらしい
var objParam = new Array();objParam["2301"]="27";・・・
objParam を辞書にする
import requests
from bs4 import BeautifulSoup
import re
def doAction(address):
arg1 = address[0]
arg2 = address[1]
with requests.post('https://www.jra.go.jp'+arg1, data='cname='+arg2) as r1:
r1.encoding = 'Shift_jis'
bs_obj = BeautifulSoup(r1.text, 'lxml')
return bs_obj
#チェックデジット辞書を作成
soup = doAction(('/JRADB/accessS.html', 'pw01skl00999999/B3'))
ss = [str(s) for s in soup.find_all('script') if 'objParam' in str(s)][0]
yymms = re.findall('(?<=\[").+?(?=\"])', ss)
cds = re.findall('(?<=\=").+?(?=\")', ss)
dict_yymm_cd = dict(zip(yymms,cds))
# 2023年1月の「過去レース結果のアドレス」を作る
address = ('/JRADB/accessS.html','pw01skl10202301/' + dict_yymm_cd ["2301"])
print(doAction(address).find('title').text)