【发布时间】:2011-11-10 08:40:10
【问题描述】:
我正在尝试解析这个 HTML 文档以获取航班、时间、起源、日期和输出的内容。
<div id="FlightInfo_FlightInfoUpdatePanel">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr class="">
<td class="airline"><img src="/images/airline logos/US.gif" title="US AIRWAYS. " alt="US AIRWAYS. " /></td>
<td class="flight">US5316</td>
<td class="codeshare">NZ46</td>
<td class="origin">Rarotonga</td>
<td class="date">02 Sep</td>
<td class="time">10:30</td>
<td class="est">21:30</td>
<td class="status">CHECK IN CLOSING</td>
</tr>
我正在使用此代码,基于 Windows phone 7 的 HTML Agility Pack 来查找和输出<td class="flight">US5316</td> 的内容
void client_DownloadStringCompleted(object sender, DownloadStringCompletedEventArgs e)
{
var html = e.Result;
var doc = new HtmlDocument();
doc.LoadHtml(html);
var node = doc.DocumentNode.Descendants("div")
.FirstOrDefault(x => x.Id == "FlightInfo_FlightInfoUpdatePanel")
.Element("table")
.Element("tbody")
.Elements("tr")
.Where(tr => tr.GetAttributeValue("td", "").Contains("class"))
.SelectMany(tr => tr.Descendants("flight"))
.ToArray();
this.scrollViewer1.Content = node;
//Added below
listBox1.itemSource = node;
}
我在 ScrollViewer 或 Listbox 中都没有得到任何结果。我想知道我使用的 linq 解析对于我提供的 HTML 是否正确?
【问题讨论】:
标签: windows-phone-7 linq-to-xml html-parsing html-agility-pack