There is a problem with using BeautifulSoup

page = urlopen('http://weather.nsu.ru').read() soup = BeautifulSoup (page, "lxml") spans = soup.find_all('span') print(str(spans[0])) 

Here in the code I want to get an element with the current temperature, but all the time I get an empty element at the output.

 <span id="temp"></span> 

Can someone tell me what's wrong?

    1 answer 1

    The problem is that the span really confusing:

      <body> <h1>Температура около НГУ <span id="temp"></span></h1> ... 

    Solution: Parsim http://weather.nsu.ru/loadata.php :

     import re import requests url = 'http://weather.nsu.ru/loadata.php' r = requests.get(url) found = re.findall(r'window.document.title\s*=[^\-\+\d\.]*([\-\+\d\.]*)', r.text) if found: print(found[0]) 

    Result:

     -9.9 
    • Thanks for the answer, just at this moment I went on this way of solving :) - Vadim