Last active
August 29, 2015 14:01
-
-
Save pydanny/c5220b7192bd943345d6 to your computer and use it in GitHub Desktop.
This is the code that Prince Robinhood Crown is trying to resolve. Please put answers in the comments.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
#-*- coding: utf-8 -*- | |
""" | |
For Python 2.7 | |
Prince's comments: | |
To be able to access systems through Facebook, I just want the code to be able to recieve the three cookies e.g | |
Cookie name: Cookie value | |
1. ACCOUNTchoice: AFx_qI673PpN | |
2.LSIID: OEMyANomfc-PjQcmKblf0mQA66E1MSg8dqai | |
3.Gase: 1:tHw_QAOXhw28wm3--IWXBMHpl0u4AQ:rb3iDL_-h66YC2Ph | |
""" | |
import os | |
import sys | |
import urllib2 | |
import cookielib | |
# create cookiejar to store cookie | |
cj=cookielib.FileCookieJar("Cookies") | |
opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
#cj = cookielib.FileCookieJar("Cookies") | |
#opener=urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
print "Cookie-count have %d cookies" % len(cj) | |
print "Getting page" | |
response = opener.open("https://google.co.ug/") | |
print response.headers | |
print "Got page" | |
print "Cookie-count %d cookies" % len(cj) | |
print cj | |
class Logger(object): | |
def __init__(self): | |
self.terminal = sys.stdout | |
self.log = open("log.dat", "w") | |
def write(self, message): | |
self.terminal.write(messsage) | |
# self.terminal.write(message) | |
self.terminal.write(message) | |
# self.log.write(message) | |
sys.stdout = Logger() | |
#f = open('log.dat','w') | |
#f.write(cj) | |
#f.close() | |
# store cookie info in mozilla | |
cj=cookielib.MozillaCookieJar('home/user/.mozilla/cookies.txt') | |
cj.load() | |
#cj = cookielib.MozillaCookieJar('/home/jo/.mozilla/cookies.txt') cj.load() | |
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
#opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) | |
r = opener.open("http://google.co.ug/") | |
#save to file | |
class Logger(object): | |
def __init__(self): | |
self.terminal = sys.stdout | |
self.log = open("log.dat", "w") | |
def write(self, message): | |
self.terminal.write(message) | |
self.log.write(message) | |
# self.terminal.write(message) | |
#self.log.write(message) | |
# IP:PORT | |
proxy_address = 'developer.facebook.com:8080' # change the IP:PORT, this one is for example | |
# create the proxy handler | |
proxy_handler = urllib2.ProxyHandler({'http':proxy_address}) | |
#proxy_handler = urllib2.ProxyHandler({'http': proxy_address}) | |
# create opener | |
opener = urllib2.build_opener(proxy_handler, urllib2.HTTPCookieProcessor(cj)) | |
#opener = urllib2.build_opener(proxy_handler, urllib2.HTTPCookieProcessor(cj)) | |
# install the opener | |
urllib2.install_opener(opener) | |
#urllib2.install_opener(opener) | |
# url to browse / visit | |
url = "http://google.co.ug/ " # change the url | |
req=urllib2.Request(url) | |
#req=urllib2.Request(url) | |
#data=req.read(url) | |
#data=urllib2.urlopen(req) | |
#print data | |
# now write the data to a text file | |
# create file handler | |
#fh = open('page.txt', 'w') | |
#data = "".join(data) |
Author
pydanny
commented
May 22, 2014
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment