列表给出另一个列表,列表中的每个项目给出另一个列表,需要在excel

时间:2015-06-25 09:25:42

标签: c# excel list html-agility-pack

我有一个迭代列表,列表和列表的问题,它们是嵌套的意味着每个列表单元格包含另一个列表:

问题在于:

我的excel文件包含页面路径,我需要添加更多单元格 这些细胞:

**admin/myPage.asp**

*add--> admin/myPage1.asp
add--> admin/myPage2.asp
add--> admin/myPage3.asp*

**admin/Dir/myPage.asp**

*add--> admin/Dir/myPage1.asp
add--> admin/Dir/myPage2.asp
add--> admin/Dir/myPage3.asp*

我搜索了这个页面:admin / myPage.asp,使用了htmlAgilityPack,找到了所有的链接,     页面,在此页面上重定向,

pages found:
 *admin/myPage1.asp
 admin/myPage2.asp
 admin/myPage3.asp*

需要在excel的此页面下注明,

然后还要搜索这些页面以获取更多链接:

pages found:
*admin/myPage1.asp
 admin/myPage2.asp
 admin/myPage3.asp*

如果找到更多链接,请注意它们

然后搜索这些页面,

直到找不到更多页面。

我被困在这里:

在嵌套列表中如何迭代每个列表和 然后找到新列表,然后迭代这个新列表, 然后找到其他列表然后迭代这个列表,

然后回到之前有待处理项目的列表。

如何在c#中执行此操作

背景: 我有一个路径列表,像这样," admin / start.asp",在excel中,有数百个 像这样,我把它们放在列表中,然后循环遍历每条路径,每条路径 有页面,在每个页面上我必须使用HtmlAgilityPack提取所有路径, 然后搜索此页面中的路径并从这些页面获取更多路径,  直到在这些页面中找不到更多路径,我必须继续搜索,但我必须这样做  在excel中记录它们。任何机构都有想法:

由于

1 个答案:

答案 0 :(得分:0)

You can try something like this:

var allListItems = new List(firstList);
for (int listItemIndex = 0; listItemIndex < allListItems.Count; listItemIndex++)
{
    allListItems.AddRange(allListItems[listItemIndex].Items);
}
foreach (var listItem in allListItems)
{
    //do something
}

With firstList being the list you start from.
This will basically do a breadth search by adding all the nested lists to allListItems and iterating through them. This works because allListItems.Count is recalculated for each iteration.
Afterwards you can just iterate through all the items and do whatever you want.