我的以下代码的迭代链接遇到“'NoneType'对象不可迭代”错误。有人可以帮忙吗?
private DataTable CSToDataTable(string csvfile)
{
Int64 row = 0;
try
{
string CSVFilePathName = csvfile; //@"C:\test.csv";
string[] Lines = File.ReadAllLines(CSVFilePathName.Replace(Environment.NewLine, ""));
string[] Fields;
Fields = Lines[0].Split(new char[] { ',' });
int Cols = Fields.GetLength(0);
DataTable dt = new DataTable();
//1st row must be column names; force lower case to ensure matching later on.
for (int i = 0; i < Cols; i++)
dt.Columns.Add(Fields[i].ToLower(), typeof(string));
DataRow Row;
for (row = 1; row < Lines.GetLength(0); row++)
{
Fields = Lines[row].Split(new char[] { ',' });
Row = dt.NewRow();
//Console.WriteLine(row);
for (int f = 0; f < Cols; f++)
{
Row[f] = Fields[f];
}
dt.Rows.Add(Row);
if (row == 190063)
{
}
}
return dt;
}
catch (Exception ex)
{
throw ex;
}
}
答案 0 :(得分:1)
您应在for
循环中使用tree.iterlinks()
:
for i in tree.iterlinks():
print(i)
输出:
(<Element style at 0x7f9e6e41ca48>, None, '/images/nav_logo229.png', 1054)
(<Element link at 0x7f9e6e406db8>, 'href', '/images/branding/product/ico/googleg_lodp.ico', 0)
...