Socket Programming

socket_programmingSocket Programming HOWTO

18.1. socket — Low-level networking interface

import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((‘’, 80))
s.send(b‘GET HTTP/1.0\n\n’)
while True:
____data = s.recv(512)    #or 1024
____if (len(data) < 1):


21.6. urllib.request — Extensible library for opening URLs

import urllib.request

url = ‘
s = urllib.request.urlopen(url)
for line in s:


import urllib.request

url = ‘

with urllib.request.urlopen(url) as f:


The with statement


import urllib.request
url = ‘
local_filename, headers = urllib.request.urlretrieve(url)

get_content_typePython: How to get the Content-Type of an URL?

Using Python to Access Web Data
Coursera, Oct 26 — Dec 14, 2015.

for bytes() or decode():

for more info on the “with” statement:


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s