1

어떻게 든 시즌과 에피소드의 번호를 위키 피 디아 테이블에서 두 개의 콤보 상자로 복사해야합니다. 하나는 계절 용이고 다른 하나는 에피소드 용입니다. 앱이 사용자가 상단 입력 상자에 즐겨보기를 입력 할 수 있도록 허용했습니다. 는 다음 시즌의 수에 따라 첫 번째 콤보 상자를 작성하고 사용자가 하나를 에피소드의 관련 번호를 선택하면 각 계절에 계절의 수와 에피소드의 수와 테이블Wikipedia 테이블의 정보를 콤보 상자에 복사하는 방법은 무엇입니까? 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 

지금까지 나는 하우투 페이지 소스도 페이지를 약간 조작 다운로드 발견했지만 나는 콤보로 계절마다 계절과 에피소드의 수를 얻기 위해 이것을 사용하는 방법을 모른다 상자. 어떤 도움도 큰 감사

코드 :

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