简体   繁体   中英

How to detect a paragraph (<p>) in vb.net on a website

I'm making an application that will log you into your mojang and then read your details. Everything is working fine, but it gives a message on the page if you entered wrong account username/pass, and I need to read that and figure out what it is, the problem is the <p> doesn't have a id. Perhaps I could insert that into the webbrowser1.document?

Code Example:

Website paragraph to check:

<p class="error">
                    Oops, unknown username or password. If you are logging in with a Mojang account make sure to use your e-mail address as username.
        </p>

As you can see the class="error" and the id is non-existent.

I have what I believe is the answer, but it does not work the way I wrote it: webbrowser1.document.findclass("error")

Try this:

For Each elem As HtmlElement In w.Document.GetElementsByTagName("p")
    If elem.GetAttribute("class") = "error" Then
        '...
    End If
Next

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM