Re: [Tutor] automate add-to-cart with python

2013-01-30 Thread Benjamin Fishbein

On Jan 29, 2013, at 11:49 PM, Marc Tompkins wrote:
 
 I'm pretty sure that's a typo.  It should say:
 python virtualenv.py
 
Woohoo!!! It works.
You're right. It worked this way and I was able to install pip.
And I got selenium to work.
Apparently the problem is that selenium isn't compatible with Python 2.5, so I 
installed 2.7 and when I typed import selenium, it worked! 
Now I just have to figure out how to write the code with the selenium module.
Thanks for your help, everyone.
Ben

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] automate add-to-cart with python

2013-01-30 Thread Walter Prins
Hi,


Now I just have to figure out how to write the code with the selenium
 module.


Install the Firefox extension/add-on Selenium IDE which will help with
that too:

http://seleniumhq.org/download/

http://seleniumhq.org/docs/02_selenium_ide.jsp#

It's effectively a browser macro recorder which can emit the action
recording in multiple languages, including 2 flavours of Python (depending
on how you're using Selenium.)

You can copy/paste the actions directly from the recorder or export them as
Python.  Set the clipboard format as Python under the
Options-Clipboard format menu, then select some recorded commands
(click, shift-click as per usual and then ctrl-c to copy and ctrl-v to
paste, or to export them click File-Export test-case as and pick one
of the Python options.

Walter
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] automate add-to-cart with python

2013-01-29 Thread Benjamin Fishbein
 
 
 A direct approach would probably use the webdriver API to automate the
 browser.  Selenium has one:
 
I decided to use Selenium. It may be overkill for this particular problem, but 
I'll want to use it for other things.
This is my first time trying to install a new module to Python. I've been 
working on it all morning with no success.
I'm on Mac OSX and I downloaded :
selenium-2.29.0.tar.gz
and then opened it to get:
selenium-2.29.0

In the README file,  it said for installing to Python, to type:
pip install -U selenium

So in terminal, I went to:

cd /Users/bfishbein/Downloads/selenium-2.29.0

and typed:
pip install -U selenium

I got:
-bash: pip: command not found
so I tried downloading pip

After downloading pip, I tried to install it:
cd /Applications/pip-1.2.1
install pip

I got this strange message:
usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
   [-o owner] file1 file2
   install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
   [-o owner] file1 ... fileN directory
   install -d [-v] [-g group] [-m mode] [-o owner] directory ...
Benjamins-MacBook-Air:pip-1.2.1 bfishbein$ 

Apparently it didn't install.
Do you know what I'm doing wrong?
Any help would be appreciated.
I didn't expect it to be so tough to install a python module.
Ben



___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] automate add-to-cart with python

2013-01-29 Thread Danny Yoo
 After downloading pip, I tried to install it:
 cd /Applications/pip-1.2.1
 install pip

 I got this strange message:
 usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
[-o owner] file1 file2
install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
[-o owner] file1 ... fileN directory
install -d [-v] [-g group] [-m mode] [-o owner] directory ...
 Benjamins-MacBook-Air:pip-1.2.1 bfishbein$

 Apparently it didn't install.
 Do you know what I'm doing wrong?
 Any help would be appreciated.
 I didn't expect it to be so tough to install a python module.


Technically, this is not pure Python code; expect some friction here
due to the different levels of technologies being interconnected.

I've been out of the Python development community for a very long
time, so hopefully someone else will help correct me.  I believe pip,
a Python package installer, should be installed by following the
instructions in:

http://www.pip-installer.org/en/latest/installing.html

Have you looked at this yet?


The error message you're seeing is conceptually due to the assumption
that install is a universal thing.  It's not.  install in the
context of the command line is something else entirely separate from
Python: it's a command to install BSD binary utilities.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] automate add-to-cart with python

2013-01-29 Thread Prasad, Ramit
Benjamin Fishbein wrote:
 
 
  A direct approach would probably use the webdriver API to automate the
  browser.  Selenium has one:
 
 I decided to use Selenium. It may be overkill for this particular problem, 
 but I'll want to use it for other
 things.
 This is my first time trying to install a new module to Python. I've been 
 working on it all morning with no
 success.
 I'm on Mac OSX and I downloaded :
 selenium-2.29.0.tar.gz
 and then opened it to get:
 selenium-2.29.0
 
 In the README file,  it said for installing to Python, to type:
 pip install -U selenium
 
 So in terminal, I went to:
 
 cd /Users/bfishbein/Downloads/selenium-2.29.0

Looks like you are on OS X. You can (probably) install pip from 
MacPorts or HomeBrew (which can also properly install alternative 
versions of Python without messing up the system installed version). 
Not that these are necessary, but they are helpful. Keep them
in mind for the future, especially if you test with multiple
versions of Python on the same machine.

 
 and typed:
 pip install -U selenium
 
 I got:
 -bash: pip: command not found
 so I tried downloading pip
 
 After downloading pip, I tried to install it:
 cd /Applications/pip-1.2.1
 install pip
 
 I got this strange message:
 usage: install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
[-o owner] file1 file2
install [-bCcpSsv] [-B suffix] [-f flags] [-g group] [-m mode]
[-o owner] file1 ... fileN directory
install -d [-v] [-g group] [-m mode] [-o owner] directory ...
 Benjamins-MacBook-Air:pip-1.2.1 bfishbein$
 
 Apparently it didn't install.
 Do you know what I'm doing wrong?
 Any help would be appreciated.
 I didn't expect it to be so tough to install a python module.

Normally you want to do `python setup.py install`
when manually installing (or similar). I think you 
should follow the pip install directions 
here: http://www.pip-installer.org/en/latest/installing.html
You need to install distribute or setuptools 
(use the source installation directions for manually
installing), but I believe the install script for pip
(not get-pip.py) will install the dependencies for you.

All of this will install to the global python install which is not
always desireable or even recommended. I would highly recommend
installing virtual env ( http://www.virtualenv.org/en/latest/ ).
This will let you install and try modules without contaminating
your global install.


~Ramit


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] automate add-to-cart with python

2013-01-29 Thread Francois Dion
On Mon, Jan 28, 2013 at 6:32 PM, Alan Gauld alan.ga...@btinternet.com wrote:
 On 28/01/13 22:51, Benjamin Fishbein wrote:
 In general, despite scouring the Internet, I haven't been able to figure
 out how to get Python to cause javascripts I find in the html to be run.


 That's because Javascript is run in the browser which has a Javascript
 interpreter built in. Python doesn't have a Javascript interpreter so can't
 run Javascript.

 But that's usually the wrong thing to do anyway so it doesn't matter. What
 you need to do is figure out what the Javascript is doing - usually sending
 some data to a server - and replicate that.

 Alternatively fire up a real browser and drive that with automation. How you
 do that will largely depend on the browser and the OS.

 Or maybe, just maybe, somebody has written a javascript interpreter in
 Python as a module that you can import. It sounds just about crazy enough
 that it might even exist! But as I said, that's probably the wrong thing to
 do...

The other way around does exists, python in your web browser:
http://brython.info

Did a quick iPhone web app that way and demoed it to our local Python
group last night:
http://raspberry-python.blogspot.com/2013/01/iphone-app-with-python.html

You could easily extend this concept where your python script server
side controls your python script client side through reverse Ajax. And
of course it's also possible to do the whole thing client side,
without a server. Works on all modern browsers too.

François

--
www.pyptug.org  -  raspberry-python.blogspot.com  -  @f_dion
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] automate add-to-cart with python

2013-01-29 Thread Benjamin Fishbein
 
 
http://www.pip-installer.org/en/latest/installing.html
 
I went to this pip site. It told me to install virtualenv.
http://www.virtualenv.org/en/latest/#installation
The virtualenv site told me:
You can install virtualenv with pip install virtualenv, or the latest 
development version with pip install 
https://github.com/pypa/virtualenv/tarball/develop.


But since I didn't yet have pip, I couldn't use it to install virtualenv.
Then it said:
You can also use easy_install, or if you have no Python package manager 
available at all, you can just grab the single file virtualenv.py and run it 
with pythonvirtualenv.py.

I don't have easy_install. When I tried to download easy_install, it came in an 
EGG format that I couldn't open despite downloading several opener apps.
I tried this page:
https://raw.github.com/pypa/virtualenv/master/virtualenv.py
I think this is what I'll have to use for installing virtualenv, but I have not 
idea what to do with it. I cut and pasted into a python file, then ran it in 
IDLE. When I ran main(), it returned the error:
Traceback (most recent call last):
  File pyshell#8, line 1, in module
virtual_1.main()
  File /Users/bfishbein/Documents/virtual_1.py, line 935, in main
sys.exit(2)
SystemExit: 2

I don't have much experience with command prompt interfaces which I think is 
causing most of my trouble. There's probably something simple I'm missing, like 
a semicolon or quotes.
Please help if you can.
Thank you,
Ben

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] automate add-to-cart with python

2013-01-29 Thread Marc Tompkins
On Tue, Jan 29, 2013 at 9:19 PM, Benjamin Fishbein
bfishbei...@gmail.comwrote:Then it said:

 You can also use easy_install, or if you have no Python package manager
 available at all, you can just grab the single file 
 virtualenv.pyhttps://raw.github.com/pypa/virtualenv/master/virtualenv.py and
 run it with pythonvirtualenv.py.


I'm pretty sure that's a typo.  It should say:
python virtualenv.py

In general, to run a Python script, the simplest (and most
usually-expected) way is to start a command prompt (a.k.a. terminal
session) and simply type the word python, followed by the name of the
script.  IDLE is meant for convenient editing and running - and it's very
far from the best tool even for that - but it is definitely NOT recommended
as a way to run production code; it introduces too much extraneous junk
into the Python environment.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] automate add-to-cart with python

2013-01-28 Thread Benjamin Fishbein
Hello,
I'm trying to automate putting a series of items into my cart. Here's the html 
for the add-to-cart button on the website:
a class=PDP_button_addToCart2 
href=http://cart.half.ebay.com/ws/eBayISAPI.dll?HalfAddItemToCartamp;ap=additemamp;itemid=343343950913amp;pr=57017296amp;fromshop=1;Add
 to cart/a/td
Using the cookielib and urllib2 module, I did:

a= text.find(href)+6
b = text.find('', a)
url = text[a:b]
new_text = opener.open(url).read()

It goes to the page that shows my cart, but there are zero items--the item is 
not added to the cart.
I'm guessing this has something to do with:

class=PDP_button_addToCart2

I'm not sure how to have Python click the button.
In general, despite scouring the Internet, I haven't been able to figure out 
how to get Python to cause javascripts I find in the html to be run.
Any help would be greatly appreciated.
Thanks,
Ben

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] automate add-to-cart with python

2013-01-28 Thread Alan Gauld

On 28/01/13 22:51, Benjamin Fishbein wrote:

In general, despite scouring the Internet, I haven't been able to figure
out how to get Python to cause javascripts I find in the html to be run.


That's because Javascript is run in the browser which has a Javascript 
interpreter built in. Python doesn't have a Javascript interpreter so 
can't run Javascript.


But that's usually the wrong thing to do anyway so it doesn't matter. 
What you need to do is figure out what the Javascript is doing - usually 
sending some data to a server - and replicate that.


Alternatively fire up a real browser and drive that with automation. How 
you do that will largely depend on the browser and the OS.


Or maybe, just maybe, somebody has written a javascript interpreter in 
Python as a module that you can import. It sounds just about crazy 
enough that it might even exist! But as I said, that's probably the 
wrong thing to do...


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] automate add-to-cart with python

2013-01-28 Thread Danny Yoo
 Or maybe, just maybe, somebody has written a javascript interpreter in
 Python as a module that you can import. It sounds just about crazy enough
 that it might even exist! But as I said, that's probably the wrong thing to
 do...

A direct approach would probably use the webdriver API to automate the
browser.  Selenium has one:

http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html

That being said, I agree with you that this is most likely an overkill
approach.  Better to see if the site has an officially supported
REST-style API that can be more easily mechanized.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] automate add-to-cart with python

2013-01-28 Thread ALAN GAULD



 Or maybe, just maybe, somebody has written a javascript interpreter in
 Python as a module that you can import. It sounds just about crazy enough
 that it might even exist! But as I said, that's probably the wrong thing to
 do...

A direct approach would probably use the webdriver API to automate the
browser.  Selenium has one:

    http://selenium.googlecode.com/svn/trunk/docs/api/py/index.html



You could use COM to drive IE on Windows or Applescript to drive 
a MacOS browser. No idea what you'd do on Linux...

But direct API or even a simple CGI url call would be better.

Alan g.

PS. 
Nice to see you posting on tutor again Danny :-)___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor