Python, trying to parse html to attain email address
Question: I am using beautifulsoup to attain an email address, however I am having
problems. I do not know where to start to parse through this, to attain the
email address.

    
    
    > #input:     url
    > #output:    address
    > 
    > def urlSC(url):
    >     soup = BeautifulSoup(urllib2.urlopen(url).read())
    >     #word =  soup.prettify() 
    >     word = soup.find_all('a')
    >     print word
    >     return word
    

OUTPUT:

    
    
    >     [<a href="default.aspx"><img alt="·Î°í" border="0" src="image/logo.gif"/></a>, <a href="http://www.ctodayusa.com"><img
    > border="0" src="image/ctodayusa.jpg"><a></a>
    >     </img></a>, <a></a>, <a href="mailto:rev_han777@yahoo.com" id="hlEmail">rev_han777@yahoo.com</a>, <a id="hlHomepage"></a>, <a
    > href="javascript:img_up('','','');"><img border="0" class="img"
    > src="upload/" vspace="10" width="1"/></a>, <a
    > href="javascript:img_up('','','');"><img border="0" class="img"
    > src="upload/" vspace="10" width="1"/></a>, <a
    > href="javascript:openWin('http://maps.yahoo.com/maps_result?addr=2100
    > De armoun Rd.&amp;csz=99515&amp;country=us')" id="hlMap"><img
    > border='0"' src="images/globe.gif"> 위치</img></a>, <a
    > href="javascript:print()"><img border="0" src="images/printer.gif">
    > 프린트</img></a>, <a href="javascript:mail_go('rev_han777@yahoo.com',
    > '2Y5E9%2bk0h%2b4P%2f0H3jEJTq9VUG%2f0gaj40')" id="hlSendMail"><img
    > border="0" src="images/mails.gif"> 메일보내기</img></a>, <a
    > href="javascript:history.go(-1)"><img border="0"
    > src="images/list.gif">
    >     </img></a>, <a href="UpdateAddress.aspx?OrgID=4102" id="hlModify"><img alt="" border="0" src="Images/Modify.gif"/></a>]
    

I want this email: rev_han777@yahoo.com


Answer: Get the `a` element by id, extract everything after `mailto:` from the `href`
attribute value:

    
    
    link = soup.find('a', id='hlEmail')
    print link['href'][7:]
    

Demo:

    
    
    >>> from bs4 import BeautifulSoup
    >>> import urllib2
    >>> url = "http://www.koreanchurchyp.com/ViewDetail.aspx?OrgID=4102"
    >>> soup = BeautifulSoup(urllib2.urlopen(url))
    >>> link = soup.find('a', id='hlEmail')
    >>> print link['href'][7:]
    rev_han seven seven seven at yahoo.com  #  obfuscated intentionally
    

