开发者

Getting Twitter news feed using Python

Hey everybody, I've been playing around with Python 2.7 and BeautifulSoup 3.2 recently and I've gotten my code to work for Facebook where it makes a POST request to Facebook to login and downloads the HTML to the page, then saves it to my computer. I tried doin开发者_运维问答g this with Twitter but it doesn't seem to be working*.. here's my code:

import urllib, urllib2
from BeautifulSoup import BeautifulSoup

#I've replaced my actual username and password for obvious reasons
form = urllib.urlencode({'username':'myUsername','password':'myPassword'})
response = urllib2.urlopen('https://mobile.twitter.com/session',form)
response = response.read()

Can anyone tell me what's wrong with it? Thanks!

*After I do response = response.read() I have it write to a file on my harddrive and open it with firefox. When I open it all I see is whatever is on http://mobile.twitter.com/ at the time of me running the script.


  • Don't use BeatufulSoup, use lxml instead http://lxml.de/ (much more powerfull, faster and convenient)
  • Don't grab twitter web-interface, use oficial twitter API instead http://dev.twitter.com/doc/get/statuses/home_timeline


You may want to check out the Twitter libraries for Python.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜