I am trying to retrieve the ID of a racehorse from netkeiba's racecard (including the past five race records).
I took it out with BeautifulSoup, but at the end I get an error.

AttributeError: ResultSet object has no attribute'find_all'.You're probably treating a list of  elements like a single element. Did you call find_all() when you meant to call find()?
Applicable source code
import requests
from bs4 import BeautifulSoup
url ='https://race.netkeiba.com/race/shutuba_past.html?race_id=202005021212&rf=shutuba_submenu'
html = requests.get(url)
html.encoding ='EUC-JP'
soup = BeautifulSoup(html.text, "html.parser")
import re
soup.find_all('div', attrs = {'class':'Horse02'}) # No error so far
#The following code gives an error and the character string containing the horse ID (number) cannot be retrieved.
soup.find_all('div', attrs = {'class':'Horse02'}).find_all('a', attrs = {'href': re.compile('^/horse')})
What I tried

Please describe what you have tried for the problem here.

Supplemental information (FW/tool ​​version, etc.)

Jupyter Lab

  • Answer # 1

    .find_all returns a list, so you need to loop around to process each item.
    Also, the regular expression to get the ID part is wrong.
    Regular expressions are an example, but for reference

    for div in soup.find_all('div', attrs = {'class':'Horse02'}):
    # 2015101654

  • Answer # 2

    lst = []
    for item in soup.find_all('div', attrs = {'class':'Horse02'}):
        lst.append(item.find('a', attrs = {'href': re.compile('^/horse')}))

    Can i go?

Related articles