나는 "Transaction의 전체 가치를 얻으려고 노력하고 있으며, HTML Agility Pack을 사용하여 url을 얻는다." 내가 HTML을 사용하여 HTML을 검사 할 때 URL과 함께 전체 트랜잭션 ID를 볼 수 있습니다. 내 질문은 어떻게 모든 트랜잭션 및 그들과 관련된 URL의 전체 값을 얻고 내 datagridusing 비동기에 추가 할 수 있습니다. "SelectNode"를 사용할 수없는 이유는 Windows 스토어 응용 프로그램에서 지원되지 않기 때문입니다. ## Heading ##
여기에 사이트의 URL이 있습니다 : http://explorer.litecoin.net/address/LeDGemnpqQjrK8v1s5HZKaDgjgDKQ2MYiK
async private void GetTransactions()
{
url = "http://explorer.litecoin.net/address/LeDGemnpqQjrK8v1s5HZKaDgjgDKQ2MYiK";
string html;
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
try
{
WebResponse x = await req.GetResponseAsync();
HttpWebResponse res = (HttpWebResponse)x;
if (res != null)
{
if (res.StatusCode == HttpStatusCode.OK)
{
Stream stream = res.GetResponseStream();
using (StreamReader reader = new StreamReader(stream))
{
html = reader.ReadToEnd();
}
HtmlDocument htmlDocument = new HtmlDocument();
htmlDocument.LoadHtml(html);
var tsTable = htmlDocument.DocumentNode.ChildNodes["html"].ChildNodes["body"].ChildNodes["div"].
ChildNodes["div"].ChildNodes["div"].ChildNodes["table"].InnerHtml;
int n = 2;
var tsRow = tsTable.Split(Environment.NewLine.ToCharArray()).Skip(n).ToArray();
for (var index = 1; index < tsRow.Count(); index++)
{
}
}
}
}
catch
{
MessageDialog messageDialog =
new MessageDialog("A tear occured in the space-time continuum. Please try again when all planets in the solar system are aligned.");
}
}
<telerikGrid:RadDataGrid Grid.RowSpan="1" ItemsSource="{Binding Data}" IsSynchronizedWithCurrentItem="True" AlternateRowBackground="AliceBlue" Background="White" Grid.Row="2"
UserEditMode="Inline" UserGroupMode="Disabled" VerticalAlignment="Bottom" AutoGenerateColumns="False" Height="294" Grid.ColumnSpan="2">
<telerikGrid:RadDataGrid.GroupDescriptors>
<telerikGrid:PropertyGroupDescriptor PropertyName="Group"/>
</telerikGrid:RadDataGrid.GroupDescriptors>
<telerikGrid:RadDataGrid.Columns>
<telerikGrid:DataGridNumericalColumn PropertyName="Id" CanUserEdit="False" CanUserFilter="False" Header="#" SizeMode="Fixed" Width="40"/>
<telerikGrid:DataGridTextColumn PropertyName="pnDate" CanUserFilter="False" Header="Date" CellContentFormat="{}{0,0:dd.MM.yyyy}"/>
<telerikGrid:DataGridNumericalColumn PropertyName="pnType" CanUserFilter="False" Header="Type"/>
<telerikGrid:DataGridTextColumn PropertyName="pnAddress" CanUserFilter="False" Header="Address"/>
<telerikGrid:DataGridDateColumn PropertyName="pnAmount" CanUserFilter="False" Header="Amount"/>
</telerikGrid:RadDataGrid.Columns>
</telerikGrid:RadDataGrid>
SelectNode (XPath 쿼리 사용)는 노드를 반복하고 일을 매칭하는 자체 작업을 수행합니다. 직접 HTML을보고 원하는 경로로 이동하면됩니다.
var table = htmlDocument.DocumentNode.ChildNodes["html"].ChildNodes["Body"].ChildNodes[0].ChildNodes[0].ChildNodes[0].ChildNodes["Table"];
이제 테이블이 생겼으므로 특정 클래스 속성 값을 가진 Div를 찾는 것처럼 ChildNodes에 좀 더 구체적 일 수있었습니다. 행을 살펴볼 수 있습니다. 첫 번째 행은 헤더이며, 우리는 그것에 대해 신경 쓰지 않습니다.
// The first table row is index 0 and looks like this:
// <tr><th>Transaction</th><th>Block</th><th>Approx. Time</th><th>Amount</th><th>Balance</th><th>Currency</th></tr>
// It is the column headers, each <th> node represents a column. The foreach below starts at index 1, the first row of real data...
foreach(var index = 1; index < table.ChildNodes.Count; index++)
{
// a row of data looks like:
// <tr><td><a href="../tx/513.cut for space.b4a#o1">5130f066e0...</a></td><td><a href="../block/c3.cut for space.c9c">468275</a></td><td>2013-11-28 09:14:17</td><td>0.3</td><td>0.3</td><td>LTC</td></tr>
// each <td> node inside of the row, is the matching data for the column index...
var row = table.ChildNodes[index];
var transactionLink = row.ChildNodes[0].ChildNodes["a"].Attributes["href"].Value;
var transactionText = row.ChildNodes[0].ChildNodes["a"].InnerText;
// Other variables for the table row data...
// Here is one more example
var apporxTime = row.ChildNodes[2].InnerText;
}
이것은 해킹의 한 지옥이지만 당신이 절대적으로 확실하게 확실하지 않은 경우 @ the_lotus 언급 한 API를 사용하지 않는 경우 다음 정규식을 사용하여 구문 분석하려고 할 수 있습니다.
\<td\>\s*\<a(?:.*)href="(?<url>[^"]*)"\>(?<block>[^<]*)\</a\>\s*\</td\>\s*\<td\>(?<date>[^<]*)\</td\>\s*\<td\>(?<amount>[^<]*)\</td\>\s*\<td\>(?<balance>[^<]*)\</td\>\s*\<td\>(?<currency>[^<]*)\</td\>