0
HTML 테이블을 텍스트 파일로 구문 분석 중이며 아래 코드 샘플입니다. cols6
또는 6 번째 <td></td>
에서, innertext는 예를 들어. 70,430
. 나는 텍스트 파일에 innertext를 작성할 때 쉼표를 무시하는 방법에 대해서는 해결하지 못했습니다. 나는 70,430
대신에 70430
만 쓰고 싶습니다. 숫자에 ,
을 없애기 위해 내가 무엇을해야합니까에 대한 cols6[j].InnerText
을 알고 싶습니까? 어떤 도움이라도 대단히 감사 할 것입니다. 고맙습니다! :)HTML 테이블 구문 분석 <td></td> InnerText Strip Punctuation (쉼표)
// Load HTML
HtmlAgilityPack.HtmlDocument doc = new HtmlAgilityPack.HtmlDocument();
doc.Load(fileName);
// Get all tables in the document
HtmlNodeCollection tables = doc.DocumentNode.SelectNodes("//table");
using (FileStream fs = new FileStream(@"..\..\bin\Debug\Pages\" + "Director.txt", FileMode.Append))
using (StreamWriter sw = new StreamWriter(fs))
{
// Iterate all rows in the relevant table
HtmlNodeCollection rows = tables[2].SelectNodes(".//tr[position() >2]");
for (int i = 0; i < rows.Count; ++i)
{
// Iterate all columns in this row
HtmlNodeCollection cols = rows[i].SelectNodes(".//td[1]");
HtmlNodeCollection cols2 = rows[i].SelectNodes(".//td[2]");
HtmlNodeCollection cols3 = rows[i].SelectNodes(".//td[3]");
HtmlNodeCollection cols4 = rows[i].SelectNodes(".//td[4]");
HtmlNodeCollection cols5 = rows[i].SelectNodes(".//td[5]");
HtmlNodeCollection cols6 = rows[i].SelectNodes(".//td[6]");
HtmlNodeCollection cols7 = rows[i].SelectNodes(".//td[7]");
for (int j = 0; j < cols.Count; ++j)
// Get the value of the column and print it
sw.WriteLine(cols[j].InnerText + "," + cols2[j].InnerText + "," + cols3[j].InnerText + "," +
cols4[j].InnerText + "," + cols5[j].InnerText + "," + cols6[j].InnerText + "," + cols7[j].InnerText + ",822");
}
sw.Flush();
sw.Close();
fs.Close();
}
이 위대한 작품! 고맙습니다. :) – Shyuan
문제 없으니 도움이 되니 기쁩니다. – scheien