LebGeeks

A community for technology geeks in Lebanon.

You are not logged in.

#1 August 4 2012

NuclearVision
Member

[Question] Data entry and fetching in Python

Hey guys,
I'm good in python when it comes to programming and GUI.
But when it comes to use python in the web i'm not that good.
So i'm seeking your help.
What i exactly want is to enter a data in a web page (by data i mean some numbers or string), then fetch the source of the next page(like if i clicked submit).

I appreciate any help,
Thanks in advance.

Last edited by NuclearVision (August 4 2012)

Offline

#2 August 5 2012

Joe
Member

Re: [Question] Data entry and fetching in Python

The best way to send data to a server (the only way?) is to encapsulate it inside an HTTP request. Here's a very brief overview of how you do this:

- on the server side: Your program receives an HTTP request, you have to read the data encapsulated in it. In python you can check out this module to find out how it's done.

- on the client side you need to insert an HTML element that will provide the user a way of inputting her data and a "submit" button. HTML forms are what you are looking for.

A few remarks:

- When you talk about the web, it's a good idea to always make the distinction between what happens on the client side (browser) and what happens on the server side.

- This is an extremely simplistic view of an actual HTTP exchange. The topic is not particularly simple, but it's not difficult. It's only the high amount of info that can be a pain.

- Modern web development will normally not deal with this right away. Instead, the developer will use a set of existing libraries that will completely abstract all these details and allow you to focus on more interesting parts. We call these "web development frameworks". The most famous ones in the Python world include Django and Flask. I suggest you start getting yourself familiar with Django, it will ease your way in the web world.

Don't hesitate to ask if anything's unclear, we could even work on some code examples.

Offline

#3 August 5 2012

NuclearVision
Member

Re: [Question] Data entry and fetching in Python

Hey rahmu,
Thanks for your post.
Isn't there any simpler way? For example, if in the page's source code there's a text box named ''value'',
couldn't i just fill it, and submit the form?
If not, i will be grateful if you give me an example for what you wrote above.

Thanks again.

Offline

#4 August 14 2012

xterm
Moderator

Re: [Question] Data entry and fetching in Python

NuclearVision,

what rahmu mentioned is correct. I would have to disagree on the choice of Django or Flask in your case.

If you're just getting started with web development (which is rather clear based on what you've mentioned so far), using a fully fledged framework such as Django (or a simpler one such as Flask) will definitely not help you on the long run. If you use Django, you'll get things done, but you will definitely not know how things are done; There's way too much magic in Django, to a point where, you would think you're using python but in fact you're simply following a convention that does things for you. Moreover, there are a lot of modules in django that you will not need or use, but the fact that they're there may scare you away.

The most important task for you to do right now as rahmu mentioned is to learn these in the following order:

1- Networking in Python : Sockets (Client/Server)

Build directory server that stores People contacts
Build a client that connects to this server and allows you to request/add contacts

Use plain sockets, do not use any remoting libraries whatsoever.

At this point you should have a small understanding about how network applications work. The 'way' your client and server are able to react to one another is basically a dialect. The dialect in the world of networking is called a Protocol. Let's call this protocol NVCP (short for NuclearVision Contacts Protocol)

2- What is HTTP?

Just as NVCP is the protocol that your server understands, HTTP is the protocol that Webservers understand. I will not elaborate on this for now, so i'll leave it up to you to read and ask questions if necessary.

3- Play with existing HTTP Clients

Use the module that rahmu suggested. This library is to a webserver, what your Contacts client is to your server. Use it to request pages from a webserver, or use it to build a terminal web browser, it's up to you.

4- Implement your own web scripts

Up to this point, you haven't created any script that runs (or is dispatched to) by/from webservers. Normally I would suggest you play around with CGI but as we're in 2012, CGI has faded away in the world of python and is replaced by WSGI.

So my final suggestion to you, is to read and play around with WSGI through this tutorial.

I promise you, once you've done these steps, you're ahead of most developers I know.

Last edited by xterm (August 14 2012)

Offline

Board footer