[Python] How to create a BeautifulSoup variable that will allow find_all to identify html table

Discussão em 'Python' iniciado por Stack, Fevereiro 13, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to create a single content variable based off of five website pages. The code I'm using is:

    soup_a = []
    for i in range(1,6):
    url_a = f'https://www.mascotdb.com/native-american-high-school?page={i}'
    resp_a = requests.get(url_a, headers=headers)
    soup_a.append(bs(resp_a.content, "html.parser"))


    This gets me the information, but I then want to use BS to combine all of the html tables into one variable that I can extract data from. The code I'm using isL

    main_table_a = soup_a.find_all("table", {"class":"table table-striped views-table views-view-table cols-5"})


    This gives me an error of "'list' object has no attribute 'find_all'". I'm assuming that my mistake is in how I'm setting up soup_a. Is there a better way to go about this?

    Continue reading...

Compartilhe esta Página