2012-10-02 36 views
1

我試圖創建一個應用程序訪問亞馬遜賣家中心:與Python

  1. 登錄到Amazon Seller Central

  2. 打開了包含在多個頁面,檢索呈現的頁面源 包括值是由人口填充javascript

  3. 解析呈現頁面源併爲用戶輸出報告。 (這部分是完整的)

我已經能夠利用Firefox的插件Firebug查看呈現的頁面源,即複製到文件手動完成這個任務,我已經寫完解析器。但是,我想讓這個過程自動化,並儘可能地與用戶分享,這些人可能不太擅長技術。

我的困難是使用Python完成步驟1和2。我一直在做很多搜索和閱讀有關使用庫urllib,urllib2和cookielib,但我一直無法弄清楚如何讓它正常工作。

例如,我在這裏發現了這個片斷計算器:

import urllib, urllib2, cookielib 

username = "xxx" 
password = "xxx" 

cj = cookielib.CookieJar() 
opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj)) 
login_data = urllib.urlencode({'username':username,'j_password':password}) 
opener.open('https://sellercentral.amazon.com/gp/homepage.html', login_data) 
resp = opener.open('https://sellercentral.amazon.com/myi/search  /ItemSummary.amzn?') 
print resp.read() 

現在,我知道我的opener.open是錯的,但我不知道在哪裏可以找到亞馬遜賣家中心的登錄腳本我需要指出這一點。

另外,我不確定我是否以正確的方式解決這個問題。任何方向都不勝感激。

回答

0

看一看這個

http://seleniumhq.org/

或者這

http://wwwsearch.sourceforge.net/mechanize/j

可能是在瀏覽器環境做你想要的東西更容易一點。

br.select_form(name="order") 
# Browser passes through unknown attributes (including methods) 
# to the selected HTMLForm. 
br["cheeses"] = ["mozzarella", "caerphilly"] # (the method here is __setitem__) 
# Submit current form. Browser calls .close() on the current response on 
# navigation, so this closes response1 
response2 = br.submit() 
+0

感謝您的資源,我會開始研究這些,看看我能否找到一種方法來做我需要的東西。 – Del