0

How can I get pokemon information in this website(https://pokehubcoordinates.com/pvp) in Vb.net? I tried two ways. but it didn't work

  1. code

      Dim sourceString As String = New System.Net.WebClient().DownloadString("https://pokehubcoordinates.com/pvp")
    
  2. code

     Dim request As WebRequest = WebRequest.Create("https://pokehubcoordinates.com/pvp")
     Using response As WebResponse = request.GetResponse()        
             Using reader As New StreamReader(response.GetResponseStream())
                     Dim html As String = reader.ReadToEnd()
                     File.WriteAllText("e:\test.html", html)
             End Using
     End Using
    
Emin Yalçın
  • 11
  • 1
  • 2
  • As all web pages that are generated by scripts, you cannot get the generated data using a WebRequest, you need something that can interpret the scripts and render a page, i.e., a compatible WebBrowser. – Jimi Aug 29 '21 at 22:52
  • yes i use cefsharp.winform (chromium) but How can I get pokemon information? – Emin Yalçın Aug 29 '21 at 23:05
  • When the HTML is generated, using standard methods as `GetElementsByTagName()`, `GetElementById()`, iterating the child elements, getting Attribute values, InnerHtml etc. or using a tool as [HtmlAgilityPack](https://html-agility-pack.net/) and XPath expressions to returns the nodes you care about. – Jimi Aug 29 '21 at 23:18
  • I'll try it tomorrow and report back. thank you – Emin Yalçın Aug 29 '21 at 23:21
  • @Jimi hi master; I tried this code. but not work. please help me. im amateur programmer. why did work? Dim webClient As New System.Net.WebClient Dim result As String = webClient.DownloadString("https://pokehubcoordinates.com/pvp") Dim values As JObject = JObject.Parse(result) Dim finalHTML As String = values.GetValue("col-lg-4 col-md-6 p-1") Dim doc = New HtmlDocument() doc.LoadHtml(finalHTML) Dim pokes = doc.DocumentNode.Elements("div").Select(Function(o) o.InnerText.Trim()) MsgBox(String.Join(",", pokes)) – Emin Yalçın Aug 30 '21 at 11:54
  • 1
    As already mentioned, you cannot use any form of WebRequest (the WebClient *internals* is still a WebRequest). You need a WebBrowser that renders the HTML, running the scripts it contains, then use the DOM of the WebBrowser's Document to call standard methods (`GetElementsByTagName()` & Co.) - if available - or get the rendered HTML document from the WebBrowser and pass it to a parser, as HtmlAgilityPack. – Jimi Aug 30 '21 at 12:07
  • i have chromium browser (cefsharp) . i see all pokemons in website in my program. but i dont know it. how i get all pokes? please give me example come? – Emin Yalçın Aug 30 '21 at 15:10
  • Well, then get the HTML Document (when completed) from your WebBrowser and pass it to HtmlAgilityPack. – Jimi Aug 30 '21 at 15:45
  • thanks master i love u. =) – Emin Yalçın Aug 30 '21 at 17:45
  • hi master @Jimi i need to help again. I change the selected one in the combobox but the pokemon do not change. this is the code i use `_browser.EvaluateScriptAsync("(function() { return document.getElementsByClassName('form-control col-3 col-sm-2')[1].selectedIndex = '1'; })();")` – Emin Yalçın Aug 31 '21 at 10:32
  • Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Aug 31 '21 at 13:32

1 Answers1

0
Sub ShowSource()
    Dim ts As Task = getSource()
End Sub


Private Async Function getSource() As Task
    Dim source As String = Await _browser.GetBrowser().MainFrame.GetSourceAsync()
    Dim dokuman As HtmlAgilityPack.HtmlDocument = New HtmlAgilityPack.HtmlDocument()
    dokuman.LoadHtml(source)
    Dim veri1 As String = dokuman.DocumentNode.SelectNodes("//*[@id=""root""]/div[4]/div/div[2]/div/div")(0).InnerText
    textbox1.text =veri1 


End Function
Emin Yalçın
  • 11
  • 1
  • 2