C# と VB.NET の質問掲示板

わんくま同盟

ASP.NET、C++/CLI、Java 何でもどうぞ

C# と VB.NET の入門サイト


(過去ログ 18 を表示中)
■7247 / )  Re[9]: MSDNの目次が欲しい
□投稿者/ YAS (21回)-(2007/09/02(Sun) 23:35:35)
> 後は自力で頑張ってみますです!

よけいなお節介だとは思いつつ,面白そうだったのでつくってみちゃいました。
フォームにコピペすれば動きます。
最後まで取得できるかどうかは試していません。(すごい時間がかかりそう...)


Public Class Form1

    Dim TreeView1 As New TreeView

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.TreeView1.Dock = DockStyle.Fill
        Me.Controls.Add(Me.TreeView1)
        Dim Tree As New TreeNode("<MSDN>")
        Me.TreeView1.Nodes.Add(Tree)
        Me.Show()
        DumpNode("http://msdn2.microsoft.com/ja-jp/library/default(d=toc).aspx", Tree, 0)
    End Sub

    Private Sub DumpNode(ByVal url As String, ByVal tree As TreeNode, ByVal i As Integer)
        If Not url.Contains("d=toc") Then
            url = IIf(url.EndsWith(").aspx"), url.Replace(").aspx", ",d=toc).aspx"), url.Replace(".aspx", "(d=toc).aspx"))
        End If
        Using Browser As New WebBrowser
            Browser.Navigate(url)
            While Browser.ReadyState < WebBrowserReadyState.Complete
                Application.DoEvents()
            End While
            Dim Nodes As HtmlElement = Browser.Document.GetElementById("ctl00_DeepTreeControl1_MtpsDeepTreen" & i.ToString & "Nodes")
            i += 1
            Dim El As HtmlElement = Me.GetElementByIdFromHtmlElements(Nodes, "ctl00_DeepTreeControl1_MtpsDeepTreet" & i.ToString)
            While El IsNot Nothing
                Dim t As TreeNode = tree.Nodes.Add(El.GetAttribute("title") & " " & El.GetAttribute("href"))
                Me.TreeView1.ExpandAll()
                If Nodes.Document.GetElementById("ctl00_DeepTreeControl1_MtpsDeepTreen" & i.ToString) IsNot Nothing Then
                    DumpNode(El.GetAttribute("href"), t, i)
                End If
                i += 1
                El = Me.GetElementByIdFromHtmlElements(Nodes, "ctl00_DeepTreeControl1_MtpsDeepTreet" & i.ToString)
            End While
        End Using
    End Sub

    Private Function GetElementByIdFromHtmlElements(ByVal el As HtmlElement, ByVal id As String) As HtmlElement
        For Each e As HtmlElement In el.All
            If e.Id = id Then Return e
        Next
        Return Nothing
    End Function

End Class

返信 編集キー/


管理者用

- Child Tree -