2013-12-08 73 views
2

我試圖將以下網站的flow.gassco.no作爲我的第一個python項目之一。我需要繞過重定向到主頁面的啓動畫面。我已經隔離了以下操作,帶重定向的Python網頁請求

<form method="get" action="acceptDisclaimer"> 
<input type="submit" value="Accept"/> 
<input type="button" name="decline" value="Decline" onclick="window.location = 'http://www.gassco.no'" /> 
</form> 

在瀏覽器中追加'acceptDisclaimer?'到網址重定向到目標flow.gassco.no。但是,如果我嘗試在urllib中複製此內容,則在輸出源文件時,我似乎保持在同一頁面上。

import urllib, urllib2 
url="http://flow.gassco.no/acceptDisclaimer?" 
url2="http://flow.gassco.no/" 
#first pass to invoke disclaimer 
req=urllib2.Request(url) 
res=urllib2.urlopen(req) 
#second pass to access main page 
req1=urllib2.Request(url2) 
res2=urllib2.urlopen(req1) 
data=res2.read() 
print data 

我懷疑我過於簡化的問題,但希望任何輸入我怎麼能接受免責聲明,繼續輸出的主要頁面的源代碼。

+2

這恰恰是你的代碼是什麼樣子?您的網址不是引號字符串(「http://flow.gassco.no/」),就像它們應該在這裏一樣。 – Totem

回答