[Python-talk] Accessing Web site via Python
Mark Mc Mahon
mark.m.mcmahon at gmail.com
Mon May 14 08:58:23 EDT 2007
Hi Peter,
See some comments below..
On 5/10/07, Peter Courlis <neat_gent at yahoo.com> wrote:
> Hello Again,
>
>
> Your Hint or suggestion as follows:
>
> Go back to
> > Using Command Prompt via windoze "start" button, then
> > start at C:\ \\then at
> > C:\cd python25
>
> Then
> C:\python25>python.exe aapl.py
>
> ^^^^^^^
> |
> i.e., tell the Python interpreter to run this:
> specify the name of your program as a PARAMETER
> to your "python.exe" command
>
> Gives Error as:
> Python.exe can't open file 'aapl.py' ErrNo 21: No such file of directory
>
This is cmd.exe (the windows DOS prompt) telling you that it did not
find appl.py in the same directory as python.exe (the directory you
are in).
So you need to tell the application you are running (Python.exe)
exactly where the file is..
so for example if aapl.py is in folder c:\documents and
settings\peterc\aapl.py you would write...
cd \python25 ## Change directory where python.exe is
python.exe "c:\Documents and Settings\peterc\aaply.py"
> Also tried independently:
> C:\python25>python.exe
> >>> \\gives prompt OK
> >>> python.exe aapl.py
> "File<stdin>" line1 in <module>
> SyntaxError invalid syntax
> >>> \\ back to prompt
> >>>aapl.py
> Traceback most
> recent call last
> "File<stdin>" line1 in <module>
> Name Error: name:aapl not defined
>
You cannot run python scripts this way - the easiest way is to run
them from the DOS prompt (c:\> )
> But Interpreter works if:
> >>>print 6+2
> 8
> >>>print 6/3
> 2
> print"Hello world"
> Hello world
>
> --------------------------------------------------
> Above are results of attempt to get interpreter to
> recognize script: aapl.py
>
> thanks Peter
>
> OBTW, know any Win-pythonista's?
>
>
I work on windows exclusively - and can try to help you
If you add .PY to your pathext variable (
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/476204 ) and
if your installation is working correctly - then it becomes even
easier to run Python programs - all you would have to do to run
appl.py is to be in the same directoyr and type:
appl ## that's it! - just like any other exe, com, bat, etc!
Look at python http://www.deadlybloodyserious.com/category/geek/python/
for more details. PLEASE PLEASE be careful if you touch your
registry!!!
Mark Mc Mahon
>
>
>
>
> Bill Sconce <sconce at in-spec-inc.com> wrote:
> Hi, Peter -
>
> I can't see whether you got my message from Tuesday night (8:02PM).
> I'll try to respond to this anyway, since you're on the right track.
>
>
>
> On Wed, 9 May 2007 03:57:48 -0700 (PDT)
> Peter Courlis wrote:
>
> > Good Morning,
> >
> > Thanks for the quick response.
> >
> > My current observations:
> >
> > Using Command Prompt via windoze "start" button, then
> > start at C:\ \\then at
> > C:\cd python25 \\ then at
> > C:\python25>python.exe \\get interpreter response
> > Python 2.5.1
> > Type "help" blah
> > >>> \\ proper prompt
>
>
>
> Go back to
> > Using Command Prompt via windoze "start" button, then
> > start at C:\ \\then at
> > C:\cd python25
>
> Then
> C:\python25>python.exe aapl.py
>
> ^^^^^^^
> |
> i.e., tell the Python interpreter to run this:
> specify the name of your program as a PARAMETER
> to your "python.exe" command
>
>
>
> There's more to explore later (PATH, double-clickability) but
> for now you probably want to just see something run...
>
> -Bill
>
>
> > >>>aapl.py
> > Traceback blah blah
> > File "", lin1 1, in
> > NameError: name 'aapl' is not defined \\ then
> >
> > >>>execfile('aapl.py')
> > Error no such file or directory
> >
> > script is actually resident in C:python25 directory
> > so assume Interpreter can see script or contents
> > of this basic directory
> >
> >
> > >>>execfile('C:python25\work\aapl.py')
> > file "", line 1
> > Syntax Error: invalid syntax
> >
> > script is actually now in C:python25\work directory so
> > assume Interpreter can see script or contents
> > of this basic directory.
> > I.E., I see this Cmd as above, providing full path to
> > Interpreter (?)
> >
> > I guess I need to investigate the status of, or
> > content of 'path variables' in windoze, because
> > 'python help' will not open either, which tells me
> > that the Cmd Line mechanism can't find it's
> > way around the python25 directory structure (on
> > this ThinkPad, with WinXP)...
> >
> >
> > peter
> >
> > Bill Sconce wrote: On Fri, 4 May 2007 06:06:19 -0700 (PDT)
>
> > Peter Courlis wrote:
> >
> > > Good Morning,
> > >
> > > A Python question?
> > >
> > > I would like to be able to go to a Web Site and
> > > grab a piece of data. For example, to go to
> > > a specific Yahoo Finance page such as,
> > > URL:http://finance.yahoo.com/q?s=AAPL
> > > [...]
> > > Is there a mechanism, methods or library code in Python to
> > > perform this capture without writing spaghetti code?
> > >
> > > Thanks in advance
> > >
> > > Jim
> >
> >
> > Hi, Peter (Jim?) -
> >
> > Yes there is. For how you might pull down the HTML, see below.
> >
> > Lloyd (the guy who signs his name as "Python") is right about parsing
> HTML;
> > i.e., using BeautifulSoup. And of course what you do with the quote data
> > after you've extracted them may be any of a number of different processes.
> >
> > The code below should give you a flavor of Python. It works. (Although you
> > probably don't want to be hitting Yahoo! every 5 seconds... :)
> >
> > -Bill
> >
> > P.S. Do come around and hang out on the list, as Lloyd suggests. You'll
> > be welcome. And welcome at our PySIG meetings too!
> >
> >
> _____________________________________________________________________
> > #! /usr/bin/env python2.5
> > """Demonstrate one possible beginning to solving Jim Courlis's poser
> > about Python and the Web.
> > (c) In Spec, Inc., Milford, NH 03055-0085 USA.
> > Released under GPL V2.
> > """
> > import urllib2, time
> >
> > def get_AAPL():
> > """Get and return current AAPL quote from Yahoo! Finance page.
> >
> > Use ad-hoc parse based on simple manual inspection of the page.
> > """
> > quote_reader =
> urllib2.urlopen('http://finance.yahoo.com/q?s=AAPL')
> > for text in quote_reader:
> > whereis = text.find('class="ygtb">Apple Inc. (AAPL)')
> > if whereis > -1:
> > # HTML where quote appears looks like "102.88"
> > start, end = '', ''
> > start = text.find(start, whereis) + len(start)
> > end = text.find('', start)
> > quote_reader.close()
> > return text[start:end]
> >
> >
> > if __name__ == '__main__':
> > # Unit-test by getting and displaying a few quotes every 5 seconds
> > more = 3
> > while 1:
> > print 'AAPL now trading at', get_AAPL()
> > more -= 1
> > if more:
> > time.sleep(5)
> > else:
> > break
> >
> >
> >
> > ---------------------------------
> > Ahhh...imagining that irresistible "new car" smell?
> > Check outnew cars at Yahoo! Autos.
>
>
>
> ________________________________
> Ahhh...imagining that irresistible "new car" smell?
> Check out new cars at Yahoo! Autos.
>
>
> _______________________________________________
> Python-talk mailing list
> Python-talk at dlslug.org
> http://dlslug.org/mailman/listinfo/python-talk
>
>
More information about the Python-talk
mailing list