答えて

2

performanceログからリダイレクトを受け取ることができます。ここdocsgithub answerに私はC#でやったさよると、Pythonでポートに可能でなければなりません:message.params.redirectResponse.urlは、元のURLと等しい場合

logsをループ
var options = new ChromeOptions(); 
var cap = DesiredCapabilities.Chrome(); 
var perfLogPrefs = new ChromePerformanceLoggingPreferences(); 
perfLogPrefs.AddTracingCategories(new string[] { "devtools.network" }); 
options.PerformanceLoggingPreferences = perfLogPrefs; 
options.AddAdditionalCapability(CapabilityType.EnableProfiling, true, true); 
ptions.SetLoggingPreference("performance", LogLevel.All); 
var driver = new ChromeDriver(options); 
var url = "https://some-website-that-will-redirect.com/"; 
driver.Navigate().GoToUrl(url); 
var logs = driver.Manage().Logs.GetLog("performance"); //all your logs with redirects will be here 

、そしてmessage.params.request.urlは、リダイレクトURL

が含まれています webdriverio使用

のNode.js:

var options = { 
    desiredCapabilities: { 
     browserName: 'chrome', 
     loggingPrefs: { 
      'browser': 'ALL', 
      'driver': 'ALL', 
      'performance': 'ALL' 
     }, 
     chromeOptions: { 
      perfLoggingPrefs: { 
       traceCategories: 'performance' 
      }, 
     } 
    } 
var client = webdriverio.remote(options); 
await client.url(url); 
var logs = await client.log('performance'); 
var navigations = parseLogs(logs, url); 

function parseLogs(logs, url) { 
    var redirectList = []; 
    while (true) { 
     var targetLog = (logs.value.find(l => { 
      if (l.message.indexOf(url) == -1) 
       return false; 
      var rootMessage = JSON.parse(l.message); 
      if (((((rootMessage || {}).message || {}).params || {}).redirectResponse || {}).url == url) 
       return true; 
      return false; 
     }) || {}).message; 
     if (!targetLog) 
      break; 
     if (redirectList.indexOf(url) != -1) 
      break; 
     redirectList.push(url); 
     var targetLogObj = JSON.parse(targetLog); 
     var nextUrl = ((((targetLogObj || {}).message || {}).params || {}).request || {}).url; 

     if (nextUrl) { 
      url = nextUrl; 
      continue; 
     } 
     break; 
    } 
    return redirectList; 
} 
+0

は、すべてのJavaを使用してこのトピックの契約上のサンプル、およびChromePerformanceLoggingPreferencesはネット。仕のようです...ありがとうc。私もwebdriverio' 'でそれをやっている – Adarsha

+0

、desiredCapabilities:{ browserName: 'クロム'、 loggingPrefs:{ 'ブラウザ': 'ALL'、 'ドライバー': 'ALL'、 のパフォーマンス ':「ALL ' }、 chromeOptions:{ perfLoggingPrefs:{ traceCategories '性能' }}} 、次いでVARログ=はclient.log待つ(' パフォーマンスを '); – Toolkit

+0

このコードはもう動作していないようです。不明なエラー:解析できません:goog:chromeOptions 不明なエラーから:perfLoggingPrefsを解析できません。 不明なエラーから:認識できないパフォーマンスログオプション:enableTimeline'は面白いですか? – Jan

関連する問題