Facebook のプロフィール ページにログインするには、次のスクリプトを使用します。
このファイルをfb_login.pyとして保存し、同じフォルダーにファイルfb_test.htmlを作成します。
ブラウザで fb_test.html を表示するか、プレーン テキストで自分の名前を検索して証明できるように、ログインに成功しました。
アプリケーションを作成するために必要なSECRET AND APIキーではなく、単純な認証資格情報でログインする方法を知っている人はいますか?
import urllib, urllib2, cookielib
user = 'put_your_mail_here'
passwd = 'put_your_password_here'
file = './fb_test.html'
url_login = "https://login.facebook.com/login.php?"
url_action = "https://login.facebook.com/login.php?login_attempt=1"
url_topic = "http://www.facebook.com/profile.php?id=___put_your_profile_Number_here"
url_index = "https://login.facebook.com/login.php?"
def login(user, password, url_action):
cj = cookielib.LWPCookieJar()
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor())
urllib2.install_opener(opener)
opener.addheaders=[('Content-Type','application/x-www-form-urlencoded'),('Connection','keep-alive'),('User-Agent','Mozilla/5.0')]
params = urllib.urlencode({'action':url_action , 'referer':url_index, 'email':user, 'pass':passwd,
'loginTrue':"login"})
f = opener.open(url_action, params)
f.close()
f = opener.open(url_action, params)
f.close()
return opener
def get_source_code( opener, url_x ):
f = opener.open(url_x)
data = f.read()
print type(data)
f.close()
return data
def keep_log( data, file ):
f = open(file, 'w')
f.write(data)
f.close()
opener = login(user, passwd, url_action)
src_code = get_source_code(opener, url_topic)
keep_log(src_code, file)
print src_code