Path: csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.027 X-Spam-Evidence: '*H*': 0.95; '*S*': 0.00; 'python.': 0.02; 'subject:Python': 0.06; 'subject:into': 0.09; 'url:github': 0.09; 'subject:How': 0.10; 'python': 0.11; '"\\n")': 0.16; 'alert': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'subject:Javascript': 0.16; 'wrote:': 0.18; "python's": 0.19; 'thanks.': 0.20; 'help.': 0.21; 'seems': 0.21; 'import': 0.22; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; "doesn't": 0.30; 'mode': 0.30; 'message- id:@mail.gmail.com': 0.30; 'url:wiki': 0.31; '>>>>': 0.31; 'skip:t 40': 0.33; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; '14,': 0.36; 'grateful': 0.36; 'subject:?': 0.36; 'hi,': 0.36; 'should': 0.36; 'to:addr:python-list': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'how': 0.40; 'read': 0.60; 'expression': 0.60; 'skip:t 30': 0.61; "you're": 0.61; 'you.': 0.62; 'skip:w 30': 0.69; 'jul': 0.74; 'addon': 0.84; 'bare': 0.84; 'subject:read': 0.84; 'do:': 0.91; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=nWwW+TTl4yrUpjARjn5YKuhxnGNoKi2n3R5w2xgfflc=; b=TrD5F11AaH4yFTQaU1su8k06mnZLEpb8pe0ZCOq9M+47dfdqCMQcGw0kRDOz/894gE jKkXj2IZh5hGUyET3w1WsH21YOzMwBbH4cNaXRCXJ3MNvcsq0FsptRlNBezd7OeLsB+1 ZpLofNgGWyrP2Bi/NiGxKCJgsNKgIFK34EyXh6nnTGAH/rj0H4snUH4xMSLlDduaOnQk dIJMT5sF225A3+pbYfu0u4i2sRNX1WHkPPqn8ErYw/4StT0jq4jq/u1xU4hS6G1q40dJ vTsFhAj829dryTuXmPZx56eMP6Qv4Wa4d+Y/4qREqMqbtXnHx2JGCtx6YTUvJmEUcq26 E1IQ== MIME-Version: 1.0 X-Received: by 10.52.120.77 with SMTP id la13mr22421949vdb.23.1373757973823; Sat, 13 Jul 2013 16:26:13 -0700 (PDT) In-Reply-To: References: Date: Sun, 14 Jul 2013 09:26:13 +1000 Subject: Re: How to read Mozrepl Javascript result into a Python Variable? From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 31 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373757983 news.xs4all.nl 15895 [2001:888:2000:d::a6]:46616 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50619 On Sun, Jul 14, 2013 at 6:49 AM, goldtech wrote: > Hi, > > With Mozrepl addon in Firefox and Python I do: > >>>> import telnetlib >>>> tn = telnetlib.Telnet(r'127.0.0.1', 4242, 5) >>>> tn.read_eager() > '\nWelcome to MozRepl.\n\n - If you get stuck at the "' >>>> tn.read_until("repl> ") > ...snip... >>>> tn.write(r'alert(window.content.location.href)'+"\n") > > and I get an alert box with the URL of the active tab. > > But how do I read that URL into a python variable? Something like tn.write(r';var zz = window.content.location.href'+ "\n") but that doesn't get it into python. > > I would be grateful for help. Thanks. This seems to be what you're after: https://github.com/bard/mozrepl/wiki/Tutorial By my reading of that, this should do it: tn.write('window.content.location.href\n') It seems to function somewhat like Python's own interactive mode - a bare expression gets sent to you. Very convenient. ChrisA