2012-03-12 61 views
2

我打算在一頁上使用斜紋來填寫表單,點擊提交按鈕,然後使用BeautifulSoup來解析生成的頁面。我怎樣才能餵養BeautifulSoup的HTML頁面?我假設我必須閱讀當前的網址,但我不知道如何實際返回網址才能這樣做。我試過斜紋的TwillBrowser.get_url(),但它只返回None。如何使用斜紋查看當前網址?

回答

0

對於任何未來的患者,我發現使用機械化而不是斜紋更好,因爲斜紋是機械化的未更新薄殼。解決方案如下:

import mechanize 

url = "foo.com" 
br = mechanize.Browser() 

br.open(url) 

br.select_form(name = "YOURFORMNAMEHERE") #make sure to leave the quotation marks 
br["YOURINPUTFIELDNAMEHERE"] = ["YOURVALUEHERE"] #this must be in a list even if it is only one value 

response = br.submit() 

print response.geturl()