how to get nested tags with a loaded html page using python or php?
Question: How to do it?

How to get nested tags with a loaded html page using python or php?

Could you give me maybe a site where I can learn?

    
    
    from HTMLParser import HTMLParser
    import urllib
    
    class MyHTMLParser(HTMLParser):
    
        def handlestarttag(self, tag, attrs):
            print "Poczatek %s" % tag
    
        def handleendtag(self, tag):
            print "Koniec %s tag" % tag
    
        def handledata(self, data):
            print "Dane %s" % data
    
    p = MyHTMLParser()
    input = urllib.urlopen('url')
    html = input.read()
    input.close()
    p.feed(html)
    


Answer: Look into [BeautifulSoup](http://www.crummy.com/software/BeautifulSoup/):

Here is an example for you:

    
    
    from bs4 import BeautifulSoup
    
    # Use urlopen to read web pages, this is only an e
    test_input = r'<html><body><div id="bar"><p>Foo</p></div></body></html>'
    soup = BeautifulSoup(test_input)
    
    print soup.find('div', {'id': 'bar'}).p.text
    

This yields:

    
    
    Foo
    

Look into the docs for BS for more examples. The important thing here is to
use an existing library, and not try to create one for your own.

