Advertisement
Guest User

Untitled

a guest
May 10th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.32 KB | None | 0 0
  1.         Public Function GetCorrectWikipediaUrl(ByVal Query As String) As String
  2.             Dim webClient As New WebClient
  3.             Dim resultString = webClient.DownloadString("https://en.wikipedia.org/w/api.php?action=opensearch&format=xml&search=" & Query & "&namespace=0&limit=1&suggest=true")
  4.             Dim xmlDocument = New XmlDocument
  5.             xmlDocument.LoadXml(resultString)
  6.             Try
  7.                 Dim searchSuggestion = xmlDocument.ChildNodes(1)
  8.                 If Not searchSuggestion Is Nothing Then
  9.                     Dim section = searchSuggestion.ChildNodes(1)
  10.                     If Not section Is Nothing Then
  11.                         Dim item = section.ChildNodes(0)
  12.                         If Not item Is Nothing Then
  13.                             Dim url = item.ChildNodes(1)
  14.                             If Not url Is Nothing Then
  15.                                 Dim urlNode = url.ChildNodes(0)
  16.                                 If Not urlNode Is Nothing Then
  17.                                     Return urlNode.Value
  18.                                 End If
  19.                             End If
  20.                         End If
  21.                     End If
  22.                 End If
  23.             Catch ex As IndexOutOfRangeException
  24.  
  25.             End Try
  26.             Return Nothing
  27.         End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement