我试图通过解析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