473,385 Members | 2,015 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

writing a web client

I want to write a program which will automatically login to my ISPs
website, retrieve data and do some processing. Can this be done? Can
you point me to any example python programs which do similar things?

Regards,
Ajar

Jul 29 '05 #1
7 2127

Ajar wrote:
I want to write a program which will automatically login to my ISPs
website, retrieve data and do some processing. Can this be done? Can
you point me to any example python programs which do similar things?

Regards,
Ajar


Very easily. Have a look at my article on the ``urllib2`` module.

http://www.voidspace.org.uk/python/articles.shtml#http

You may need to use ClientCookie/cookielib to handle cookies and may
have to cope with BASIC authentication. There are also articles about
both of these as well.

If you want to handle filling in forms programattically then the module
ClientForm is useful (allegedly).

Best Regards,

Fuzzyman
http://www.voidspace.org.uk/python

Jul 29 '05 #2
fuzzy's urllib2 info is excellent. The other way peopel snarf stuff
over HTTP and FTP is using 'wget' or 'libcurl'. THere's

http://pycurl.sourceforge.net/

Jul 29 '05 #3
Jay
thats pretty cool, could someone post a example program of a python
web-based program?

Jul 29 '05 #4
Jay
thats pretty cool, could someone post a example program of a python
web-based program?

Jul 29 '05 #5
"Fuzzyman" <fu******@gmail.com> writes:
Ajar wrote:
I want to write a program which will automatically login to my ISPs
website, retrieve data and do some processing. Can this be done? Can
you point me to any example python programs which do similar things?

Regards,
Ajar


Very easily. Have a look at my article on the ``urllib2`` module.

http://www.voidspace.org.uk/python/articles.shtml#http

You may need to use ClientCookie/cookielib to handle cookies and may
have to cope with BASIC authentication. There are also articles about
both of these as well.

If you want to handle filling in forms programattically then the module
ClientForm is useful (allegedly).


The last piece of the puzzle is BeautifulSoup. That's what you use to
extract data from the web page.

For instance a lot of web pages listing data have something like this
on it:

<table>
....
<tr><th>Item:</th><td>Value</td></tr>
....
</table>

You can extract value from such with BeautifulSoup by doing something like:

soup.fetchText('Item:')[0].findParent(['td', 'th']).nextSibling.string

Where this checks works for the item being in either a td or th tag.

Of course, I recommend doing things a little bit more verbosely. In my
case, I'm writing code that's expected to work on a large number of
web pages with different formats, so I put in a lot of error checking,
along with informative errors.

links = table.fetchText(name)
if not links:
raise BadTableMatch, "%s not found in table" % name
td = links[0].findParent(['td', 'th'])
if not td:
raise BadmatchTable, "td/th not a parent of %s" % name
next = td.nextSibling
if not next:
raise BadTableMatch, "td for %s has no sibling" % name
out = get_contents(next)
if not out:
raise BadTableMatch, "no value string found for %s" % name
return out

BeautifulSoup would raise exceptions if the conditions I check for are
true and I didn't check them - but the error messages wouldn't be as
informative.

Oh yeah - get_contents isn't from BeautifulSoup. I ran into cases
where the <td> tag held other tags, and wanted the flat text
extracted. Couldn't find a BeautifulSoup method to do that, so I wrote:

def get_contents(ele):
"""Utility function to return all the text in a tag."""

if ele.string:
return ele.string # We only have one string. Done
return ''.join(get_contents(x) for x in ele)

<mike
--
Mike Meyer <mw*@mired.org> http://www.mired.org/home/mwm/
Independent WWW/Perforce/FreeBSD/Unix consultant, email for more information.
Jul 29 '05 #6
Here:
http://diveintopython.org/http_web_s...html#oa.divein

Here:
Cookbook rel 2, and:
http://aspn.activestate.com/ASPN/Coo...Python?kwd=Web

Here:other really good py intros which cover 2.2 / urllib (maybe 2.3, I
don't have them with me), but examples should all not give deprecation
warnings: Practical Py (Hetland), Text Processing (Mertz).

Jul 30 '05 #7
EP
Prabahar wrote:
I want to know difference between
Python-cgi and Perl-cgi and also I want
to which one is efficient from the performance.

The difference between a cgi program written in Perl and a cgi program written in Python is the choice of programming language. Both work quite well.You probably want to use whichever programming language you like best, and that can only be discovered from writing programs in both.

In terms of "efficient" (efficiency) , are you talking about how much memory the program uses, how fast the program executes, or how much time it takes to write and debug the program? There are differences between the two in these regards, but I do not have any reliable information that quantifiesthose differences, and the differences are likely to vary greatly depending on the nature and length of the program, and how efficiently written the code is.

I think, generally, if you really like programming in Perl, there is probably no reason not to use it (at least for typical/short cgi programs) - it has been the default choice for years; conversely, if you really like programming in Python, you will probably be happy to tackle any challenges associated with using it for cgi.
Notes:
Perl cgi execution is generally offered by all hosts that offer cgi; Pythoncgi execution is offered by fewer hosts (but some of those hosts are really great).

With either language, if execution "performance" is a concern, you may wantto use something along the lines of mod_python or mod_perl which embed a persistent interpreter in your web server. This lets you avoid the overhead of starting an external interpreter and avoids the penalty of Perl/Python start-up time, giving faster time to execution.

Was this at all the information you were looking for? Why do I think you may have intended a very technical question? If so, you may have to be a little more specific about the sort of differences you are interested in understanding.
Eric
Jul 30 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: MB | last post by:
I am writing an FTP Client using the NIO packages because I want to use the non-blocking functionality. I have done this successfully except for the fact that after I "put" an image file to the...
385
by: Xah Lee | last post by:
Jargons of Info Tech industry (A Love of Jargons) Xah Lee, 2002 Feb People in the computing field like to spur the use of spurious jargons. The less educated they are, the more they like...
7
by: Sidd | last post by:
Hi, I tried finding and example of multithreaded client-serve program in python. Can any one please tell me how to write a multithreaded client-server programn in python such that 1.It can handle...
0
by: Marc Schumacher via DotNetMonster.com | last post by:
Hi, I am writing a client/server application with a desktop and a pocketPC which transfers a xml string which is to be loaded by a dataset on the client. the server uses this code to...
6
by: rekaeps | last post by:
We are developing an ASP.NET 2.0 (C#) application, and I'm having troubles sending e-mail from the server when accessing the web site from a separate client computer. Also, in the same scenario,...
20
by: Vincent Delporte | last post by:
Hello I'm about to write a prototype for a business application, but since this my first real web application, I'm looking for a good book or article that sums up the different issues web...
5
by: vijay.db | last post by:
Hi Group, I'm running DB2 UDB Enterprise Edition V7.1 in AIX 4.3.3.0. And database backups goes to the TSM server. We have the following TSM Client API installed in the server: ...
11
by: Krzysztof Retel | last post by:
Hi guys, I am struggling writing fast UDP server. It has to handle around 10000 UDP packets per second. I started building that with non blocking socket and threads. Unfortunately my approach...
1
by: Jean-Paul Calderone | last post by:
On Fri, 21 Nov 2008 00:20:49 -0200, Gabriel Genellina <gagsl-py2@yahoo.com.arwrote: If you want to try this program out on POSIX, make sure you change the time.clock() calls to time.time() calls...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.