我試圖使用Python的請求模塊訪問網站,但我不斷收到重定向到不同的頁面。我是新手,所以我不知道從哪裏開始解決問題。Python請求模塊 - 繞過ADF環回腳本訪問網站
我的代碼是:
import requests
r = requests.get('https://swiftlink.enbridge.com/portal/')
print r.text
然而,而不是打印網頁上的文字,我得到一個輸出開始:
<html lang="en-US"><head><script>
/*
** Copyright (c) 2008, Oracle and/or its affiliates. All rights reserved.
*/
/**
* This is the loopback script to process the url before the real page loads. It introduces
* a separate round trip. During this first roundtrip, we currently do two things:
* - check the url hash portion, this is for the PPR Navigation.
* - do the new window detection
* the above two are both controled by parameters in web.xml
*
* Since it's very lightweight, so the network latency is the only impact.
*
* here are the list of will-pass-in parameters (these will replace the param in this whole
* pattern:
* viewIdLength view Id length (characters),
* loopbackIdParam loopback Id param name,
* loopbackId loopback Id,
* loopbackIdParamMatchExpr loopback Id match expression,
* windowModeIdParam window mode param name,
* windowModeParamMatchExpr window mode match expression,
* clientWindowIdParam client window Id param name,
* clientWindowIdParamMatchExpr client window Id match expression,
* windowId window Id,
* initPageLaunch initPageLaunch,
* enableNewWindowDetect whether we want to enable new window detection
* jsessionId session Id that needs to be appended to the redirect URL
* enablePPRNav whether we want to enable PPR Navigation
*
*/
有點谷歌搜索後,我發現,我正在重定向到Oracle ADF環回腳本頁面,但我一直無法找到解決方法。我試過在我的代碼中禁止重定向,但是這只是讓我找到頁面,指出我正在尋找的頁面已經暫時移動了。我知道我使用的網址是有效的,因爲它將我帶到了正確的頁面。
嗅探到這個使用Firebug或谷歌Chrome開發者工具獲取URL所做的所有網絡請求。然後你就可以說出發生了什麼。您發佈的html代碼還包含一個javascript,它會調用具有特定參數的另一個重定向,您需要了解該參數的調用並在進行原始請求調用後手動進行該調用。此外,您需要爲此使用[請求會話](http://docs.python-requests.org/en/latest/user/advanced/#session-objects)對象。 –