我试图通过解析 HAR 文件来获取每个页面的总加载时间。我找到了一个代码段,其中总时间是通过从页面开头减去最后一次获取的时间来找到的。到目前为止,一切都很好。
我有一个遍历所有页面的外部循环。
List<HarPage> pages = log.getPages().getPages();
for (HarPage page : pages)
{
/ confirms that I go through all the pages
writer.println("\n\n***\n Top of page loop, Page Number :" + pageNumber);
}
/* The problem is that I would like to process all the entries for one page at a time. This inner loop is not working properly and seems to go through the entries for all the pages. The calling sequence is as follows:
*/
List<HarPage> pages = log.getPages().getPages();
for (HarPage page : pages)
{
HarEntries entries = log.getEntries();
List<HarEntry> entryList = entries.getEntries();
int entryIndex = 0;
for (HarEntry entry : entryList) {
/ print entry number to see how many entries it processes
writer.println("Page Number: " + pageNumber + " Entry: " + entryIndex++);
entryIndex++;
}
}
我在第一页中有 124 个条目(我通过http://www.softwareishard.com/har/viewer/处理文件确认了这一点,但我的程序将遍历所有页面的 1305 个条目。
谢谢,塔里克·巴德沙
PS我发现Entry entry.getPageRef()中有一个字段。当我转到下一页时,情况会发生变化。所以也许这可以用作退出内部循环的触发器。如果有人有更优雅的解决方案请评论 TB