用户身份验证和Python中的文本解析

1 python authentication http urllib2

好吧,我正在制作一个多阶段的程序......我无法完成第一阶段的工作.我想要做的是登录Twitter.com,然后阅读用户页面上的所有直接消息.

最终我将阅读所有寻找某些事情的直接消息,但这应该不难.

到目前为止这是我的代码

import urllib
import urllib2
import httplib
import sys

userName = "notmyusername"
password  = "notmypassword"
URL = "http://twitter.com/#inbox"

password_mgr = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_mgr.add_password(None, "http://twitter.com/", userName, password)
handler = urllib2.HTTPBasicAuthHandler(password_mgr)
pageshit = urllib2.urlopen(URL, "80").readlines()
print pageshit
Run Code Online (Sandbox Code Playgroud)

因此,对我所做的错误的一点见解和帮助将会非常有帮助.

Luc*_*nes 5

Twitter不使用HTTP基本身份验证来验证其用户.在这种情况下,使用Twitter API会更好.

将Python与Twitter API结合使用的教程如下:[ http://www.webmonkey.com/tutorial/Get_Started_With_the_Twitter_API](http://www.webmonkey.com/tutorial/Get_Started_With_the_Twitter_API()