2015-10-30 106 views
1

我觀察在Chrome瀏覽器開發工具系列的重定向,「網絡」選項卡上的網絡請求:停止在瀏覽器開發工具

enter image description here

我需要能夠經過暫停重定向鏈請求已出現在「網絡」中(以便我可以將其複製爲cURL),但在執行之前。像「暫停任何網絡活動」。我在Chrome開發工具,Firefox Web Developer,Firebug,Safari中搜索了這個功能 - 但無濟於事。最接近的是螢火蟲中的「暫停XHR」,但這些重定向不是XHR。

如果能夠完成這項工作,我會接受非瀏覽器解決方案(腳本?),儘管我覺得這應該可以通過瀏覽器開發工具來實現。

回答

1

我無法找到瀏覽器解決方案。如果您對非瀏覽器解決方案還滿意,那麼在重定向之後有一個python腳本(它也使用requests庫),直到找到一些後綴並打印cURL的請求。

#!/usr/bin/env python 

import requests 
import sys 

def formatRequestAscURL(request): 
    command = "curl -X {method} -H {headers} -d '{data}' '{url}'" 
    method = request.method 
    url = request.url 
    data = request.body 
    headers = ["{0}: {1}".format(k, v) for k, v in request.headers.items()] 
    headers = " -H ".join(headers) 
    return command.format(method=method, headers=headers, data=data, url=url) 


def followUntilSuffix(startURL, suffix): 
    response = requests.get(startURL, allow_redirects=False) 
    session = requests.Session() 
    requests_iter = session.resolve_redirects(response, response.request) 

    for r in requests_iter: 
     if r.request.path_url.endswith(suffix): 
      print formatRequestAscURL(r.request) 
      return 

    print 'Required redirect isn\'t found' 


if len(sys.argv) < 3: 
    print 'This script requires two parameters:\n 1) start url \n 2) url suffix for stop criteria' 
    sys.exit() 

startURL = sys.argv[1] 
stopSuffix = sys.argv[2] 

followUntilSuffix(startURL, stopSuffix) 
+0

只要使用fiddler2就足夠了嗎? –

+0

@JanDvorak你能詳細解釋一下嗎? –

相關問題