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