Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/vb.net/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Vb.net 如何将Wikipedia表中的信息复制到组合框中?Visual Basic.Net_Vb.net_Winforms_Visual Studio 2010_Wikipedia_Server.transfer - Fatal编程技术网

Vb.net 如何将Wikipedia表中的信息复制到组合框中?Visual Basic.Net

Vb.net 如何将Wikipedia表中的信息复制到组合框中?Visual Basic.Net,vb.net,winforms,visual-studio-2010,wikipedia,server.transfer,Vb.net,Winforms,Visual Studio 2010,Wikipedia,Server.transfer,需要以某种方式将维基百科表中每个季度的季数和集数复制到两个组合框中。一个用于四季,另一个用于剧集。应用程序应该允许用户在顶部输入框中输入他们的收藏夹。 然后在第一个组合框中填入季节数,当用户选择其中一个时,将显示相关的剧集数 链接到包含季节数和每个季节的剧集数的表格: 代码: 到目前为止,我已经了解了如何下载页面源代码,甚至可以稍微操纵页面,但我不知道如何使用它将每个季度的季数和集数放入组合框中。任何帮助都很好,谢谢 代码: 此代码获取站点中表的内容并将其呈现给页面。您可以添加一些额外的代码来

需要以某种方式将维基百科表中每个季度的季数和集数复制到两个组合框中。一个用于四季,另一个用于剧集。应用程序应该允许用户在顶部输入框中输入他们的收藏夹。 然后在第一个组合框中填入季节数,当用户选择其中一个时,将显示相关的剧集数

链接到包含季节数和每个季节的剧集数的表格:

代码:

到目前为止,我已经了解了如何下载页面源代码,甚至可以稍微操纵页面,但我不知道如何使用它将每个季度的季数和集数放入组合框中。任何帮助都很好,谢谢

代码:


此代码获取站点中表的内容并将其呈现给页面。您可以添加一些额外的代码来交互这些表,以获得所需的详细信息

' Create a request for the URL.             
    Dim request As WebRequest = WebRequest.Create("http://en.wikipedia.org/wiki/List_of_House_episodes#Series_overview_and_ratings")
    ' If required by the server, set the credentials.    
    request.Credentials = CredentialCache.DefaultCredentials
    ' Get the response.    
    Dim response__1 As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
    ' Display the status.    
    Console.WriteLine(response__1.StatusDescription)
    ' Get the stream containing content returned by the server.    
    Dim dataStream As Stream = response__1.GetResponseStream()
    ' Open the stream using a StreamReader for easy access.    
    Dim reader As New StreamReader(dataStream)
    ' Read the content.    
    Dim responseFromServer As String = reader.ReadToEnd()
    ' Display the content.    
    Console.WriteLine(responseFromServer)
    ' Cleanup the streams and the response.    
    reader.Close()
    dataStream.Close()
    response__1.Close()

    'reads the html into an html document to enable parsing    
    Dim doc As IHTMLDocument2 = New HTMLDocumentClass()
    doc.write(New Object() {responseFromServer})
    doc.close()

    'loops through each element in the document to check if it qualifies for the attributes to be set    
    For Each el As IHTMLElement In DirectCast(doc.all, IHTMLElementCollection)
        ' check to see if all the desired attributes were found with the correct values    
        Dim qualify As Boolean = True
        If el.tagName = "TABLE" Then
            Dim meta As HTMLTableClass = DirectCast(el, HTMLTableClass)
            Response.Write(el.outerHTML)


        End If
    Next

看看HtmlAgilityPack,运行这段代码需要什么样的导入和引用?
Imports System.Text.RegularExpressions

Public Class Form1
Dim sourcecode As String
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
sourcecode = ((New Net.WebClient).DownloadString("http://en.wikipedia.org/wiki/List_of_House_episodes#Series_overview_and_ratings "))

Dim Code As String
Dim Information As MatchCollection = Regex.Matches(sourcecode, "<td>(.*?)</td>", RegexOptions.None)
For Each Info In Information
Code = Regex.Replace(Info.ToString, "td>", "", RegexOptions.None)
Code = Regex.Replace(Code, "</td>", "", RegexOptions.None)
MsgBox(Code)
Next
End Sub
End Class
' Create a request for the URL.             
    Dim request As WebRequest = WebRequest.Create("http://en.wikipedia.org/wiki/List_of_House_episodes#Series_overview_and_ratings")
    ' If required by the server, set the credentials.    
    request.Credentials = CredentialCache.DefaultCredentials
    ' Get the response.    
    Dim response__1 As HttpWebResponse = DirectCast(request.GetResponse(), HttpWebResponse)
    ' Display the status.    
    Console.WriteLine(response__1.StatusDescription)
    ' Get the stream containing content returned by the server.    
    Dim dataStream As Stream = response__1.GetResponseStream()
    ' Open the stream using a StreamReader for easy access.    
    Dim reader As New StreamReader(dataStream)
    ' Read the content.    
    Dim responseFromServer As String = reader.ReadToEnd()
    ' Display the content.    
    Console.WriteLine(responseFromServer)
    ' Cleanup the streams and the response.    
    reader.Close()
    dataStream.Close()
    response__1.Close()

    'reads the html into an html document to enable parsing    
    Dim doc As IHTMLDocument2 = New HTMLDocumentClass()
    doc.write(New Object() {responseFromServer})
    doc.close()

    'loops through each element in the document to check if it qualifies for the attributes to be set    
    For Each el As IHTMLElement In DirectCast(doc.all, IHTMLElementCollection)
        ' check to see if all the desired attributes were found with the correct values    
        Dim qualify As Boolean = True
        If el.tagName = "TABLE" Then
            Dim meta As HTMLTableClass = DirectCast(el, HTMLTableClass)
            Response.Write(el.outerHTML)


        End If
    Next