How to Use ANSI for Remote Screen Scraping?

Henry Chang goldspin at gmail.com
Sun Nov 2 02:03:24 CET 2008


Using the below script, I can use pexpect to correctly output the entire
remote terminal content to screen.
At this point, I am running into difficulty to scrap the screen, for the
screen elements that I want.  (Say: the screen region from the complete 3rd
line to the 8th line.)  I believe I need to use ANSI module.  I tried a few
things, but have run out of ideas.

Can anyone please help?  How can the code below be modified to use ANSI?

Thanks so much for any help.


import pexpect

child = pexpect.spawn ('ssh dummy_user at dummy_ip')
child.expect ('Password: ')

child.sendline ('dummy_password')
child.expect ('[513] ')

child.sendline ('w2ktt')  # windows 2000 terminal type
child.expect ('Command:')

child.sendline ('dummy_command')
child.expect('non-guest room')

# This will output the console to the screen.
print child.before

child.expect('Command:')
child.sendline ('logoff')
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20081101/f178613f/attachment.html>


More information about the Python-list mailing list