如果你想登录到你的 facebook 个人资料页面,我已经设法使用这个脚本来做到这一点:
将此文件另存为fb_login.py并在同一文件夹中创建一个文件fb_test.html
我成功登录,您可以通过在浏览器上查看 fb_test.html 或以纯文本搜索您的姓名来证明这一点。
有谁知道如何使用简单的 Authedication 凭据而不是使用您需要制作应用程序的 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