Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Function GetCorrectWikipediaUrl(ByVal Query As String) As String
- Dim webClient As New WebClient
- Dim resultString = webClient.DownloadString("https://en.wikipedia.org/w/api.php?action=opensearch&format=xml&search=" & Query & "&namespace=0&limit=1&suggest=true")
- Dim xmlDocument = New XmlDocument
- xmlDocument.LoadXml(resultString)
- Try
- Dim searchSuggestion = xmlDocument.ChildNodes(1)
- If Not searchSuggestion Is Nothing Then
- Dim section = searchSuggestion.ChildNodes(1)
- If Not section Is Nothing Then
- Dim item = section.ChildNodes(0)
- If Not item Is Nothing Then
- Dim url = item.ChildNodes(1)
- If Not url Is Nothing Then
- Dim urlNode = url.ChildNodes(0)
- If Not urlNode Is Nothing Then
- Return urlNode.Value
- End If
- End If
- End If
- End If
- End If
- Catch ex As IndexOutOfRangeException
- End Try
- Return Nothing
- End Function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement