import urllib.request, urllib.error, urllib.parse, http.cookiejar
jar = http.cookiejar.CookieJar()
opener = urllib.request.build_opener(urllib.request.HTTPCookieProcessor(jar))
How to use Python to log into Facebook/Myspace and crawl the content?