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


Groups > comp.lang.python > #50615 > unrolled thread

How to read Mozrepl Javascript result into a Python Variable?

Started bygoldtech <leegold@operamail.com>
First post2013-07-13 13:49 -0700
Last post2013-07-14 09:26 +1000
Articles 2 — 2 participants

Back to article view | Back to comp.lang.python


Contents

  How to read Mozrepl Javascript result into a Python Variable? goldtech <leegold@operamail.com> - 2013-07-13 13:49 -0700
    Re: How to read Mozrepl Javascript result into a Python Variable? Chris Angelico <rosuav@gmail.com> - 2013-07-14 09:26 +1000

#50615 — How to read Mozrepl Javascript result into a Python Variable?

Fromgoldtech <leegold@operamail.com>
Date2013-07-13 13:49 -0700
SubjectHow to read Mozrepl Javascript result into a Python Variable?
Message-ID<f8a064ee-d7b1-49da-856c-1139041d4b8a@googlegroups.com>
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.
 

[toc] | [next] | [standalone]


#50619

FromChris Angelico <rosuav@gmail.com>
Date2013-07-14 09:26 +1000
Message-ID<mailman.4689.1373757982.3114.python-list@python.org>
In reply to#50615
On Sun, Jul 14, 2013 at 6:49 AM, goldtech <leegold@operamail.com> 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

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web