[Tutor] Fw: running a javascript script with python
ALAN GAULD
alan.gauld at btinternet.com
Fri Nov 2 09:56:35 CET 2012
forwarding to group.
Please use Reply ALL in replies to tutor.
Alan Gauld
Author of the Learn To Program website
http://www.alan-g.me.uk/
----- Forwarded Message -----
>From: Benjamin Fishbein <bfishbein79 at gmail.com>
>To: Alan Gauld <alan.gauld at btinternet.com>
>Sent: Friday, 2 November 2012, 3:55
>Subject: Re: [Tutor] running a javascript script with python
>
>
>>
>> We need a lot more context and precision.
>>
>> What OS, what web framework(if any) what Python version.
>> I'm on a Mac using OSX. Default web browser is Safari. Python 2.5.4
>
>> What does on a web site mean?
> I mean when I use the web browser it works the second time I click the input button, but without a button to click, it continues to return an error.
>> How are you submitting text?
> Post method.
>> Who created the Javascript - how does it relate to your Python code?
>
>> How are you running the Python code?
> I'm running it in Idle.
>
>Here's what it looked like:
>
>Python 2.5.4 (r254:67917, Dec 23 2008, 14:57:27)
>[GCC 4.0.1 (Apple Computer, Inc. build 5363)] on darwin
>Type "copyright", "credits" or "license()" for more information.
>
> ****************************************************************
> Personal firewall software may warn about the connection IDLE
> makes to its subprocess using this computer's internal loopback
> interface. This connection is not visible on any external
> interface and no data is sent to or received from the Internet.
> ****************************************************************
>
>IDLE 1.2.4
>>>> import urllib,urllib2,cookielib
>>>> cj=cookielib.CookieJar()
>>>> opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
>>>> isbns='''1561380156
>0440574358
>0152590366
>0060109726
>0394531892
>9780684836287
>9780140114331'''
>>>> data={"bb_isbns":isbns}
>>>> encoded_data=urllib.urlencode(data)
>>>> url='http://www.textbooks.com/BuyBack-Search.php'
>>>> text=opener.open(url,encoded_data).read()
>>>> if "Error: BB-09-00-05" in text:
> print "The error is there."
>
>
>The error is there.
>>>> for i in range(10):
> text=opener.open(url,encoded_data).read()
> if "Error: BB-09-00-05" in text:
> print "The error is there. Attempt #",(i+1)
> else:
> print "It worked!"
> print text
>
>
>The error is there. Attempt # 1
>The error is there. Attempt # 2
>The error is there. Attempt # 3
>The error is there. Attempt # 4
>The error is there. Attempt # 5
>The error is there. Attempt # 6
>The error is there. Attempt # 7
>The error is there. Attempt # 8
>The error is there. Attempt # 9
>The error is there. Attempt # 10
>
>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20121102/6541eb68/attachment.html>
More information about the Tutor
mailing list