[Python] Why does text not being crawled? [duplicate]

Discussão em 'Python' iniciado por Stack, Março 7, 2025.

  1. Stack

    Stack Membro Participativo

    I tried crawling with Python but it didn't work. No text is loaded.

    I want to crawl a website, but it doesn't work. I can access the link and load the code, but the text is not loaded. In fact, there is data here <p class="bkt" id="mealList"> {here} </p>, but it is not loaded. Is it not loaded originally?

    Original html code:

    ...

    <p class="bkt" id="mealList"> rice/chicken/egg/greensalad/orangesaladsource/1066kcal/52g </p>

    ...

    import requests
    from bs4 import BeautifulSoup

    url = 'https://dorm.pusan.ac.kr/mdorm/main'

    headers = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.36'
    }

    response = requests.get(url, headers=headers)

    if response.status_code == 200:
    soup = BeautifulSoup(response.content, 'html.parser')
    meal = soup.find_all("p", id="mealList")
    print(meal)
    else:
    print('error')

    Continue reading...

Compartilhe esta Página