pythonweb-scrapingscraperwiki

Using ScraperWiki to get information from a div element


Is there a way to get the data out of a div-container with ScraperWiki? I've got a line of HTML that is something like:

<div id="karte_data_aktuelle_temperatur___CHA" class="karte_text_hidden">
    <span style="font-size: 10px;">9.0</span>
    <br/>
</div>

and I would like to scrape the ...CHA and 9.0. The value (9.0) isn't a problem, since that can be done by CSS selectors, but how can I get the ...CHA value?


Solution

  • I realize that this isn't scraperwiki, but BeautifulSoup, check it out anyways.

    html = r"""<div id="karte_data_aktuelle_temperatur___CHA" class="karte_text_hidden">
        <span style="font-size: 10px;">9.0</span>
        <br/>
    </div>"""
    
    
    from bs4 import BeautifulSoup
    
    soup = BeautifulSoup(html)
    elem = soup.find('div')
    
    print elem['id'], 'is the id'
    print elem.text, 'is the value' #9.0