我試圖使用python mechanize來檢索iTunes連接上的應用程序列表。一旦檢索到這個列表,將用這些鏈接進行進一步的工作。蟒蛇機械化會議未保存
登錄成功,但隨後當我按照「管理您的應用程序」鏈接時,我被重定向回登錄頁面。就好像會話丟失一樣。
import mechanize
import cookielib
from BeautifulSoup import BeautifulSoup
import html2text
filename = 'itunes.html'
br = mechanize.Browser()
cj = cookielib.LWPCookieJar()
br.set_cookiejar(cj)
br.set_handle_equiv(True)
br.set_handle_redirect(True)
br.set_handle_referer(True)
br.set_handle_robots(False)
br.set_handle_refresh(mechanize._http.HTTPRefreshProcessor(), max_time=1)
br.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
br.open('https://itunesconnect.apple.com/WebObjects/iTunesConnect.woa')
br.select_form(name='appleConnectForm')
br.form['theAccountName'] = username
br.form['theAccountPW'] = password
br.submit()
apps_link = br.find_link(text='Manage Your Applications')
print "Manage Your Apps link = ", apps_link
req = br.follow_link(text='Manage Your Applications')
for app_link in br.links():
print "link is ", app_link
任何想法可能是錯的什麼?
何時應該保存/加載餅乾罐? – Inn0vative1 2012-03-19 22:55:34
您應該儘早加載它,可能會在創建後立即加載,並在程序退出時保存它 – 2012-03-19 23:00:42
第一次運行加載將失敗,因爲該文件不存在,因此您可能需要嘗試/除非該代碼在該位置附近 – 2012-03-19 23:01:34