U
U
Uno di Palermo2018-03-12 10:01:56
Python
Uno di Palermo, 2018-03-12 10:01:56

Why doesn't bs4 ( BeautifulSoup ) see the [ div class="h1" ] element?

Hello, here is the following:
for example, there is a page:
www.irk.gov.ru/events/news/detail.php?ID=19587
news title - in

<div class="h1">В своих избирательных округах проведут ближайшую неделю депутаты Законодательного Собрания </div>

However, running the code:
import requests
from bs4 import BeautifulSoup
import sys, traceback 


def main():
    try: 
        r = requests.get('http://www.irk.gov.ru/events/news/detail.php?ID=19587',  'html.parser')
        soup = BeautifulSoup(r.content, 'html.parser')
        for i in soup.find_all('div', class_="h1"):
            title = i.text
            print(title) #(если  print(i) - то <div class="h1">Просмотр новости</div>)
            input()
    except Exception:
        print(traceback.format_exception(*sys.exc_info())[1])
        input("End ")

gives some kind of "News view", which is not even in the source code of the page

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Ruslan., 2018-03-12
@LaRN

It is possible that this div is filled with a script at the moment the page is loaded into the browser, then at the time of your request the div is still empty and contains the default value "View News"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question