Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #91190

Re: Extract email address from Java script in html source using python

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <anthra.norell@bluewin.ch>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.001
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'url:pypi': 0.03; 'interpreter.': 0.07; 'prefix': 0.07; 'pypi': 0.07; 'skip:\\ 10': 0.07; "'.'": 0.09; 'format:': 0.09; 'subject:script': 0.09; 'subject:using': 0.09; 'translator': 0.09; 'python': 0.11; 'subject:python': 0.14; 'def': 0.14; "'';": 0.16; '23,': 0.16; 'decode': 0.16; 'received:195.186': 0.16; 'received:bluewin.ch': 0.16; 'subject:Java': 0.16; 'wrote:': 0.16; 'translation': 0.16; 'basically': 0.18; 'beginner': 0.18; 'script.': 0.18; 'language': 0.19; '>>>': 0.20; 'prevent': 0.20; 'skip:" 40': 0.20; 'trying': 0.22; 'java': 0.22; 'exec': 0.22; 'code,': 0.23; 'code.': 0.23; '2015': 0.23; 'for?': 0.23; 'sat,': 0.23; 'import': 0.24; 'header :In-Reply-To:1': 0.24; 'developing': 0.25; 'script': 0.25; 'header :User-Agent:1': 0.26; 'chris': 0.26; 'error': 0.27; 'coding': 0.27; 'this.': 0.28; 'regular': 0.29; 'url:se': 0.29; "skip:' 10": 0.30; 'print': 0.31; 'url:mailman': 0.31; 'code': 0.31; 'embedded': 0.32; 'url:python': 0.33; 'extract': 0.33; 'add': 0.34; 'needed': 0.34; 'url:listinfo': 0.35; 'to:addr:python-list': 0.35; 'done': 0.35; 'path': 0.35; 'being': 0.36; 'text': 0.36; 'url:org': 0.36; 'totally': 0.36; 'subject:: ': 0.37; 'delete': 0.37; 'level': 0.37; 'stuff': 0.38; 'doing': 0.38; 'pm,': 0.39; 'to:addr:python.org': 0.39; 'received:192': 0.39; 'some': 0.40; 'hope': 0.61; 'helps': 0.61; 'address': 0.61; 'entire': 0.61; 'here.': 0.61; 'sample': 0.62; 'more': 0.62; 'needing': 0.63; 'charset:windows-1252': 0.65; 'virtually': 0.66; 'received:ch': 0.67; 'email name:info': 0.74; 'below:': 0.75; 'trial': 0.81; 'chrisa': 0.84; 'subject:source': 0.84; 'syntax?': 0.84
Date Sun, 24 May 2015 19:48:27 +0200
From Friedrich Rentsch <anthra.norell@bluewin.ch>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.7.0
MIME-Version 1.0
To python-list@python.org
Subject Re: Extract email address from Java script in html source using python
References <CAAXuHoeJ-YMQDB85qLDJ_o+9CrsfwLvm9wuOaRtbSj-i9kBaFA@mail.gmail.com> <CAPTjJmqBDu0nB2u_mf7KMpFzxxJFUqB7o-7dJiGgu-xyOL2uzg@mail.gmail.com> <CAAXuHod4NH74+VK1EY78-vCOyiOA3879qp1uPqKOFit7qVE5sQ@mail.gmail.com>
In-Reply-To <CAAXuHod4NH74+VK1EY78-vCOyiOA3879qp1uPqKOFit7qVE5sQ@mail.gmail.com>
Content-Type text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding 7bit
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.20+
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.26.1432489776.5151.python-list@python.org> (permalink)
Lines 109
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1432489776 news.xs4all.nl 2885 [2001:888:2000:d::a6]:38692
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:91190

Show key headers only | View raw



On 05/23/2015 04:15 PM, savitha devi wrote:
> What I exactly want is the java script is in the html code. I am trying for
> a regular expression to find the email address embedded with in the java
> script.
>
> On Sat, May 23, 2015 at 2:31 PM, Chris Angelico <rosuav@gmail.com> wrote:
>
>> On Sat, May 23, 2015 at 4:46 PM, savitha devi <savithad8@gmail.com> wrote:
>>> I am developing a web scraper code using HTMLParser. I need to extract
>>> text/email address from java script with in the HTMLCode.I am beginner
>> level
>>> in python coding and totally lost here. Need some help on this. The java
>>> script code is as below:
>>>
>>> <script type='text/javascript'>
>>>   //<!--
>>>   document.getElementById('cloak48218').innerHTML = '';
>>>   var prefix = '&#109;a' + 'i&#108;' + '&#116;o';
>>>   var path = 'hr' + 'ef' + '=';
>>>   var addy48218 = '&#105;nf&#111;' + '&#64;';
>>>   addy48218 = addy48218 + 'tsv-n&#101;&#117;r&#105;&#101;d' + '&#46;' +
>>> 'd&#101;';
>>>   document.getElementById('cloak48218').innerHTML += '<a ' + path + '\'' +
>>> prefix + ':' + addy48218 + '\'>' + addy48218+'<\/a>';
>>>   //-->
>> This is deliberately being done to prevent scripted usage. What
>> exactly are you needing to do this for?
>>
>> You're basically going to have to execute the entire block of
>> JavaScript code, and then decode the entities to get to what you want.
>> Doing it manually is pretty easy; doing it automatically will
>> virtually require a language interpreter.
>>
>> ChrisA
>> --
>> https://mail.python.org/mailman/listinfo/python-list
>>

This is just about nuts and bolts, not about the ethics of presumed 
intentions.

Hope it helps one way or other

Frederic


------------------------------------------------------------------------------- 


sample = '''//<!--
  document.getElementById('cloak48218').innerHTML = '';
  var prefix = '&#109;a' + 'i&#108;' + '&#116;o';
  var path = 'hr' + 'ef' + '=';
  var addy48218 = '&#105;nf&#111;' + '&#64;';
  addy48218 = addy48218 + 'tsv-n&#101;&#117;r&#105;&#101;d' + '&#46;' +
'd&#101;';
  document.getElementById('cloak48218').innerHTML += '<a ' + path + '\'' +
prefix + ':' + addy48218 + ''>' + addy48218+'<\/a>';
  //-->'''

 >>> import SE  # Download from PyPi at https://pypi.python.org/pypi/SE

 >>> def make_se_translator ():

     # Make SE substitutions
     subs_list = []

     # Make &# code substitutions
     for i in range (256):
         subs_list.append ('&#%d;=%c' % (i, chr(i)))

     # Delete Java stuff
     subs_list.append (' "document.getElementById(\'cloak48218\').=" ')
     subs_list.append (' "var =" "\n=" //<!--= //-->= ')

     # Java syntax? Tweaks needed to get the sample working
     subs_list.append (' "+ \'\'\'=" \'\'>\'=\'>\' <\/=</ ')

     # Add more as needed trial and error style
     # subs_list.append ( . . . format: ' old=new "delete this=" '

     # Make text
     subs = '\n'.join (subs_list)

     # Make SE translator
     translator = SE.SE (subs)

     # return translator, subs   # print subs, if you want to see what 
they look like
     return translator


 >>> translator = make_se_translator ()

 >>> translation = translator (sample)

 >>> print translation   # See
  innerHTML = ''; prefix = 'ma' + 'il' + 'to'; path = 'hr' + 'ef' + '='; 
addy48218 = 'info' + '@'; addy48218 = addy48218 + 'tsv-neuried' + '.' 
+'de'; innerHTML += '<a ' + path  +prefix + ':' + addy48218 + '>' + 
addy48218+'</a>';

 >>> exec (translation.lstrip ())

 >>> print innerHTML
<a href=mailto:info@tsv-neuried.de>info@tsv-neuried.de</a>

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

Re: Extract email address from Java script in html source using python Friedrich Rentsch <anthra.norell@bluewin.ch> - 2015-05-24 19:48 +0200

csiph-web