extract contact information from html with python
Question: Here is a sample html

    
    
    <div class="yui3-u-5-6" id="browse-products">
    <div id="kazbah-contact">
      <span class="contact-info-title">Contact 00Nothing:</span>
      <a href="mailto:info@00nothing.com">info@00nothing.com</a> | 800-410-2074
       | C/O Score X Score
        &nbsp;8118-D Statesville Rd
        ,
      Charlotte,
      NC
      28269
    </div>
    <div class="clearfix"></div>
    

I want to extract the contact information here, email, phone, and address. How
should I do that with python? Thanks


Answer: I use this code to extract information

    
    
    # _*_ coding:utf-8 _*_
    import urllib2
    import urllib
    import re
    from bs4 import BeautifulSoup
    import sys
    reload(sys)
    sys.setdefaultencoding('utf-8')
    
    def grabHref(url,localfile):
        html = urllib2.urlopen(url).read()
        html = unicode(html,'gb2312','ignore').encode('utf-8','ignore')
        soup = BeautifulSoup(html)
        myfile = open(localfile,'wb')
        for link in soup.select("div >            a[href^=http://www.karmaloop.com/kazbah/browse]"):
            for item in BeautifulSoup(urllib2.urlopen(link['href']).read()).select("div > a[href^=mailto]"):
                contactInfo = item.get_text()
                print link['href']
                print contactInfo
    
            myfile.write(link['href'])
            myfile.write('\r\n')
            myfile.write(contactInfo)
            myfile.write('\r\n')
        myfile.close()
    
    
    
    def main():
        url = "http://www.karmaloop.com/brands"
        localfile = 'Contact.txt'
        grabHref(url,localfile)
    if __name__=="__main__":
        main()
    

But I still can only get email address here, how can I get phone number and
address? Thanks

