2011-03-11 62 views
0
Twitter的新聞提要

嘿,大家,我一直在使用Python 2.7和3.2 BeautifulSoup玩弄最近,我已經得到了我的代碼爲Facebook工作,在那裏做一個POST請求給Facebook登錄並下載HTML到頁面,然後將其保存到我的電腦。我試圖與Twitter這樣做,但它似乎並不奏效* ..這裏是我的代碼:獲取使用Python

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() 

誰能告訴我有什麼錯呢?謝謝!

*我做響應= response.read()後,我把它寫在我的硬盤文件,用Firefox打開它。當我打開它時,我看到的是當我運行腳本時http://mobile.twitter.com/上的任何內容。

+1

當你說它不工作,你是什麼意思?你看到了什麼結果? – 2011-03-11 21:58:23

+0

我做了response = response.read()之後,我將它寫入到我的硬盤上的一個文件並用firefox打開它。當我打開它時,我看到的是http://mobile.twitter.com/上運行腳本時的所有內容。 – adelbertc 2011-03-11 22:00:52

+1

爲什麼不使用更好的api? http://dev.twitter.com/pages/libraries#python? – Nix 2011-03-11 22:14:52

回答