【发布时间】:2015-01-07 17:56:13
【问题描述】:
我制作了一个 WinForms 应用程序,它可以从网站上的表格中获得一个姓名列表。我目前正在使用 WebBrowser 和 Timer。我认为这可以做得更顺畅、更快。 WebBrowser 运行缓慢(旧的 Internet Explorer 内置),有时无法获取数据,我必须再次运行计时器。
所以我有一个 ListBox(应该包含名称)。 ListBox 称为 PlayerList。 然后我有一个按钮,它可以激活计时器来获取数据。这是我的计时器代码。
private void UpdatePlayers_Tick(object sender, EventArgs e)
{
PlayerList.Items.Clear();
if (this.Tibia.ReadyState == WebBrowserReadyState.Complete)
{
foreach (HtmlElement cell in this.Tibia.Document.GetElementsByTagName("tr"))
{
string cls = cell.GetAttribute("className");
if (cls.StartsWith("Odd"))
{
dynamic oldname = cell.InnerText;
string[] strings = oldname.Split('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
string charnameonly = strings[0];
this.PlayerList.Items.Add(charnameonly);
}
else if (cls.StartsWith("Even"))
{
dynamic oldname = cell.InnerText;
string[] strings = oldname.Split('0', '1', '2', '3', '4', '5', '6', '7', '8', '9');
string charnameonly = strings[0];
this.PlayerList.Items.Add(charnameonly);
}
}
}
}
我想知道是否有人可以帮助我实现这一目标,而无需 WebBrowser 或类似的东西。一些代码示例会非常好。
注意:我只想要玩家的名字。这是我从中获取数据的网站:http://www.tibia.com/community/?subtopic=worlds&world=Antica
【问题讨论】: