[Tutorial]Using urllib in python

Prince

[ Verified Seller ]
Staff member
Trusted Seller
Joined
11 yrs. 6 mth. 26 days
Messages
5,381
Reaction score
18,380
Age
45
Wallet
11,590$
What is urllib?:
This allows you to interact and basically use python as a web browser. It can do almost everything you can do on the web browser but it's done without a GUI and through the python shell. With this you can do things likeRead html source code
Perform browser based actions
Insert and modify headers
Get status codes of web pages
Login/registerThat's just a jist of things I can think of that you would use in the hacking community. Now let me show you some examples of usage and how to apply these things.

If we need to read
Code:
Please, Log in or Register to view codes content!
This is the basic syntax you need before you begin doing anything. Before you can read the source code, before you can do anything you need to open the url. Now don't let this fool you. It will not open a url in your webbrowser, but within the python shell to be used.

After you have your url opened you can now play with it.
So lets say we want to read the source code it would like a little something like this. (This code has been taken from my LFI filter tool I am currently working on)
Code:
Please, Log in or Register to view codes content!
As you can see I have defined a variable named valid_url which I created using urllib.urlopen(raw_input('Url to be entered'))
The input was returned as valid_url.
So valid_url.readlines()
is using the readlines() to do just what it says it's doing and thats reading the lines of the url source code.
After it's done reading the lines we now have the info we need.
The code is pretty self explanatory so I really don't know how to go into great detail with it? So there's an example of getting the source code.
 
Top Bottom