1

需要以某種方式將每個季節的季節和劇集數量從維基百科表格複製到兩個組合框中。一個是季節,另一個是情節。應用程序應該允許用戶在頂部輸入框中輸入他們偏愛的節目。 然後隨季節的數量填充第一組合框和當用戶選擇一個事件的相關數目被示如何將維基百科表中的信息複製到組合框? Visual Basic.Net

鏈接表,在每個季節的季節的數目和發作次數: http://en.wikipedia.org/wiki/List_of_House_episodes#Series_overview_and_ratings

代碼:

Public Class Form1 
Dim Search As String 
Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress 
Search = TextBox1.Text 
Search = Search.Replace(" ", "+") 
Search = "http://www.google.com/search?btnI=I'm+Feeling+Lucky&q=" & Search & "episode+list+wikipedia" 

If Asc(e.KeyChar) = 13 Then 

WebBrowser1.Navigate(Search) 
TextBox1.Text = Search 

End If 
End Sub 
End Class 

到目前爲止,我已經找到了HOWTO下載網頁的源文件,甚至操縱頁面一點,但我不知道如何使用它來獲取季節發作的次數在每個賽季打入組合框。任何幫助將是巨大的感謝

代碼:

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 
+0

看看HtmlAgilityPack。 –

回答

0

此代碼抓取站點的表的內容,並將其提交到頁面。你可以添加一些額外的代碼來交流你的表格以獲得你正在尋找的細節。

' 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 
+0

運行此代碼需要什麼樣的導入和引用? – PeterCo