这个问题确实很复杂, 用正则表达式是解决不了的, 用下面的代码可以解决
在页面分别放置 Button, WebBrowser, TextBox(多行)
private void button1_Click(object sender, EventArgs e)
{
webBrowser1.Navigate("http://datainfo.stock.);
}
private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
{
HtmlDocument doc = webBrowser1.Document;
HtmlElementCollection tables = doc.Body.GetElementsByTagName("TABLE");
StringBuilder sb = new StringBuilder();
foreach (HtmlElement table in tables)
{
HtmlElementCollection rows = table.GetElementsByTagName("TR");
for (int i = 0; i < rows.Count; i++)
{
HtmlElement row = rows[i];
HtmlElementCollection cells = row.GetElementsByTagName("TD");
if (i == 0 && cells.Count != 8)
break;
for (int j = 0; j < cells.Count; j++)
{
HtmlElement cell = cells[j];
if (i == 0 && j == 0 && cell.InnerText != "股票名称")
break;
if(j<cells.Count-1)
{
sb.Append(cell.InnerText);
sb.Append(" ");
}
else
{
sb.AppendLine(cell.InnerText);
}
}
}
}
textBox1.Text = sb.ToString();
}