2014-05-22 4 views
0

현재 Selenium을 Firebug, NetExport 및 Python에서 (시험 사용) FireStarter를 실행하여 URL의 네트워크 트래픽을 얻으려고합니다. 나열된 디렉토리에 HAR 파일이 나타나기를 기대하지만 아무것도 표시되지 않습니다. Firefox에서 테스트하고 UI를 통해 HAR 파일을 내보내고 저장하면 코드 자체가 예상대로 작동한다는 것을 알 수 있습니다. 여러 예제를 본 후에 나는 내가 누락 된 부분을 보지 못했습니다.Firebug + NetExport + FireStarter가있는 Selenium Webdriver가 Python에서 har 파일을 생성하지 않습니다.

나는 파이어 폭스 29.0.1 방화범 1.12.8 방화범 0.1a6 NetExport 사용하고 0.9b6

다른 사람이 문제가 발생 했습니까? 나는 "webFile.txt"파일을 올바르게 채우고 있습니다.

각 버전의 추가 기능을 살펴본 후에는 사용중인 Firefox 버전과 호환되는 것으로 간주됩니다. 그러나 Firefox 버전 20을 사용해 보았지만 도움이되지 않았습니다. 현재 소스 코드를 가져 왔습니다.

또한 Firestarter를 사용하거나 사용하지 않고 시험해 보았습니다. 두 경우 모두 수동으로 페이지를 새로 고쳐서 HAR을 생성하려고 시도했습니다.

내 코드는 다음과 같습니다

import urllib2 
import sys 
import re 
import os 
import subprocess 
import hashlib 
import time 
import datetime 
from browsermobproxy import Server 
from selenium import webdriver 
import selenium 
a=[]; 
theURL=''; 
fireBugPath = '/Users/tai/Documents/workspace/testSelenium/testS/firebug.xpi'; 
netExportPath = '/Users/tai/Documents/workspace/testSelenium/testS/netExport.xpi'; 
fireStarterPath = '/Users/tai/Documents/workspace/testSelenium/testS/fireStarter.xpi'; 

profile = webdriver.firefox.firefox_profile.FirefoxProfile(); 
profile.add_extension(fireBugPath); 
profile.add_extension(netExportPath); 
profile.add_extension(fireStarterPath); 

#firefox preferences 
profile.set_preference("app.update.enabled", False) 
profile.native_events_enabled = True 
profile.set_preference("webdriver.log.file", "/Users/tai/Documents/workspace/testSelenium/testS/webFile.txt") 
profile.set_preference("extensions.firebug.DBG_STARTER", True); 

profile.set_preference("extensions.firebug.currentVersion", "1.12.8"); 
profile.set_preference("extensions.firebug.addonBarOpened", True); 
profile.set_preference("extensions.firebug.addonBarOpened", True); 
profile.set_preference('extensions.firebug.consoles.enableSite', True)       


profile.set_preference("extensions.firebug.console.enableSites", True); 
profile.set_preference("extensions.firebug.script.enableSites", True); 
profile.set_preference("extensions.firebug.net.enableSites", True); 
profile.set_preference("extensions.firebug.previousPlacement", 1); 
profile.set_preference("extensions.firebug.allPagesActivation", "on"); 
profile.set_preference("extensions.firebug.onByDefault", True); 
profile.set_preference("extensions.firebug.defaultPanelName", "net"); 

#set net export preferences 
profile.set_preference("extensions.firebug.netexport.alwaysEnableAutoExport", True); 
profile.set_preference("extensions.firebug.netexport.autoExportToFile", True); 
profile.set_preference("extensions.firebug.netexport.saveFiles", True); 

profile.set_preference("extensions.firebug.netexport.autoExportToServer", False); 
profile.set_preference("extensions.firebug.netexport.Automation", True); 
profile.set_preference("extensions.firebug.netexport.showPreview", False); 
profile.set_preference("extensions.firebug.netexport.pageLoadedTimeout", 15000); 
profile.set_preference("extensions.firebug.netexport.timeout", 10000); 

profile.set_preference("extensions.firebug.netexport.defaultLogDir", "/Users/tai/Documents/workspace/testSelenium/testS/har"); 
profile.update_preferences(); 
browser = webdriver.Firefox(firefox_profile=profile); 


def openURL(url,s): 
    theURL = url; 
    time.sleep(6); 
    #browser = webdriver.Chrome(); 
    browser.get(url); #load the url in firefox 
    time.sleep(3); #wait for the page to load 
    browser.execute_script("window.scrollTo(0, document.body.scrollHeight/5);") 
    time.sleep(1); #wait for the page to load 
    browser.execute_script("window.scrollTo(0, document.body.scrollHeight/4);") 
    time.sleep(1); #wait for the page to load 
    browser.execute_script("window.scrollTo(0, document.body.scrollHeight/3);") 
    time.sleep(1); #wait for the page to load 
    browser.execute_script("window.scrollTo(0, document.body.scrollHeight/2);") 
    time.sleep(1); #wait for the page to load 
    browser.execute_script("window.scrollTo(0, document.body.scrollHeight);") 
    searchText=''; 
    time.sleep(20); #wait for the page to load 
    if(s.__len__() >0): 
     for x in range(0, s.__len__()): 
      searchText+= ("" + browser.find_element_by_id(x)); 
    else: 
     searchText+= browser.page_source; 

     a=getMatches(searchText) 
    #print ("\n".join(swfLinks)); 
    print('\n'.join(removeNonURL(a))); 
    # print(browser.page_source); 
    browser.quit(); 
    return a; 
def found_window(name): 
     try: browser.switch_to_window(name) 
     except NoSuchWindowException: 
      return False 
     else: 
      return True # found window 
def removeFirstQuote(tex): 
    for x in tex: 
     b = x[1:]; 
     if not b in a: 
      a.append(b); 
    return a; 
def getMatches(t): 
    return removeFirstQuote(re.findall('([\"|\'][^\"|\']*\.swf)', t)); 
def removeNonURL(t): 
    a=[]; 
    for b in t: 
     if(b.lower()[:4] !="http"): 
      if(b[0] == "//"): 
       a.append(theURL+b[2:b.__len__()]); 
      else: 
       while(b.lower()[:4] !="http" and b.__len__() >5): 
        b=b[1:b.__len__()]; 
       a.append(b); 
     else: 
      a.append(b); 
    return a; 

openURL("http://www.chron.com",a); 
+0

이 코드는 실제로 잘 실행되지만 다른 버전의 브라우저에서/xpi 파일을 사용하고있었습니다. 파이어 폭스에서 xpi 파일을 다시 설치하고 출력 파일을 출력합니다. – Tai

답변

2

내가 브라우저를 닫기 전에 긴 대기를 설정하여 내 자신의 일을 위해이 문제를 해결했습니다. 나는 현재 프로그램이 종료 된 후에 export하기 위해 netexport를 설정하고 있다고 생각합니다. 그래서 어떤 파일도 작성되지 않습니다. 이 원인이 라인은 다음과 같습니다 netexport source code에서

profile.set_preference("extensions.firebug.netexport.pageLoadedTimeout", 15000); 

우리가 pageLoadedTimeout가 '로드 페이지를 선언하는 마지막 페이지 요청 후 기다리는 시간 (밀리 초)`번호는 것을 가지고있다. 따라서 모든 부 페이지로드로 인해 netexport가 파일을 쓸 충분한 시간을 갖지 못하는 것으로 생각됩니다. 주의해야 할 점은 10 초 후에 시스템이 자동으로 내보내도록 설정했기 때문에 왜 절반로드 된 json 파일을 얻지 못하는지 잘 모르겠습니다.

+0

안녕하십니까, 응답 해 주셔서 감사합니다. 나는 그것이 실제로 사용하고있는 xpi 파일과 브라우저에 연결된 하나의 xpi 파일에 대해 2 개의 다른 방화 광 버전을 가지고있는 문제라는 것을 발견했다. 위의 코드는 이제 나를 위해 잘 실행됩니다. – Tai

관련 문제