[Python] Trying to create a BeautifulSoup content variable from multiple urls

Discussão em 'Python' iniciado por Stack, Fevereiro 11, 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

    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 = bs(resp_a.content, "html.parser")


    This code does the trick in creating the content variable soup_a, but it overwrites every time the loop executes, so the only data in the variable is from the final url. I tried creating a blank [] before the loop and appending the results to it, but that just gives me a list. I'm at a loss as to how to run this to where the variable soup_a would contain data from all five urls.

    Continue reading...

Compartilhe esta Página