[Tutor] CGI-version not working while
similar command-line script is fine
Kent Johnson
kent_johnson at skillsoft.com
Mon Sep 6 14:59:52 CEST 2004
Ah. I tried it in IDLE and had the same problem. Using popen4() to look at
stderr, I found that lynx is not finding the .cfg file. Adding that to the
command line made it work:
>>> i,o=os.popen4(r'C:\Downloads\Apps\LYNX\LYNX.EXE -dump
http://www.google.com')
>>> o.read()
'\nConfiguration file ./lynx.cfg is not available.\n\n'
>>> os.popen(r'C:\Downloads\Apps\LYNX\LYNX.EXE
-cfg=C:\Downloads\Apps\LYNX\LYNX.CFG -dump http://www.google.com').read()
" Google\n\n Web [1]Images
[2]Groups [3]News [4]Froogle [5]more
\xaf\n\n [6]_______________________________________________________\n
[7]Google Search [8]I'm Feeling Lucky [9]Advanced
Search\n [10]Preferences\n [11]Language
Tools\n\n [12]Advertising Programs - [13]Business Solutions - [14]About
Google\n\n \xa92004 Google - Searching 4,285,199,774 web
pages\n\nReferences\n\n 1.
http://www.google.com/imghp?hl=en&tab=wi&ie=UTF-8\n 2.
http://www.google.com/grphp?hl=en&tab=wg&ie=UTF-8\n 3.
http://www.google.com/nwshp?hl=en&tab=wn&ie=UTF-8\n 4.
http://www.google.com/froogle?hl=en&tab=wf&ie=UTF-8\n 5.
http://www.google.com/options/index.html\n 6. form field = text entry
field\n 7. form field = submit button\n 8. form field = submit
button\n 9. http://www.google.com/advanced_search?hl=en\n 10.
http://www.google.com/preferences?hl=en\n 11.
http://www.google.com/language_tools?hl=en\n 12.
http://www.google.com/ads/\n 13. http://www.google.com/services/\n 14.
http://www.google.com/about.html\n"
>>>
So try adding the -cfg switch to specify your lynx.cfg. If that doesn't
work use popen3 or popen4 to capture stderr and see what is there.
Kent
At 09:19 AM 9/6/2004 +0100, Gerhard Venter wrote:
>Hi Kent
>
>No, although I did not have the "http://" in my email, I did enter it in
>my web form. So it isn't that. (And my version of Lynx doesn't
>require it)
>
>But the interesting thing is that the line below which you suggested
>works in a Python command prompt, but not in Idle or Pythonwin.
>Perhaps CGI has the same limitation as these tools.
>print os.popen(r'c:\bin\lynx.exe -dump http://www.google.com').read()
>
>Likewise (I've resorted to using a temp file, but even that isn't
>working), the line below works in a Python command prompt but not in CGI.
>os.system(r'start /B c:\bin\lynx.exe -dump http://www.google.com >
>"F:\logs\temp.txt"')
>
>Gerhard
>
>
>
>Kent Johnson wrote:
>
>>I just tried this with Lynx Version 2.8.4rel.1-mirabilos:
>> > lynx --dump www.google.com
>>
>>I didn't get any output. If I try
>> > lynx --dump http://www.google.com
>>then it works. Could it be that simple?
>>
>>Also this works for me:
>> >>> import os
>> >>> print os.popen(r'C:\Downloads\Apps\LYNX\LYNX.EXE -dump
>> http://www.google.com').read()
>>
>>Kent
>>
>>At 05:08 PM 9/5/2004 +0100, Gerhard Venter wrote:
>>
>>>Hi Kent
>>>
>>>Thanks - my code is below. It should output a plain text version of any
>>>website
>>>
>>>G
>>>
>>>Kent Johnson wrote:
>>>
>>>>This should work. My guess is you have an error in your script, maybe a
>>>>problem with quoting or string substitution. Can you show us the script
>>>>that is having trouble?
>>>
>>>import cgi, os
>>>import cgitb; cgitb.enable()
>>>
>>>form = cgi.FieldStorage()
>>>website = form["websitename"].value
>>>command = 'lynx --dump ' + website
>>>k=os.popen(command, 'r')
>>>
>>>print 'Content-type: text/plain'
>>>print
>>>
>>>#print command (this shows the right thing- for example lynx --dump
>>>www.google.com)
>>>for line in k.readlines():
>>> print(line)
>>>_______________________________________________
>>>Tutor maillist - Tutor at python.org
>>>http://mail.python.org/mailman/listinfo/tutor
>>
>>
>
>_______________________________________________
>Tutor maillist - Tutor at python.org
>http://mail.python.org/mailman/listinfo/tutor
More information about the Tutor
mailing list