Beautifulsoup scraping specific table in page with multiple tables

To only get the first table you can use a CSS Selector nth-of-type(1):

import requests
from bs4 import BeautifulSoup

URL = "https://en.wikipedia.org/wiki/List_of_multiple_Olympic_gold_medalists"

soup = BeautifulSoup(requests.get(URL).content, "html.parser")

table = soup.select_one("table.wikitable:nth-of-type(1)")
trs = table.find_all("tr")

for tr in trs:
    print(tr.text)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top