Consider the following annotations:
<li>
<b>Username:</b> <!-- Use XPath to obtain this element. -->
" user" <!-- This is the next sibling. -->
</li>
With these annotations in mind:
You can obtain the <b>
element using XPath as you have done already and then access the username or password text by means of the NextSibling
property like so:
Dim username =
htmldoc.DocumentNode.SelectSingleNode(
"//ul/li/b[text()='Username:']").NextSibling.InnerHtml
Dim password =
htmldoc.DocumentNode.SelectSingleNode(
"//ul/li/b[text()='Password:']").NextSibling.InnerHtml
If you want to access the second occurrence of the element instead of the first, then you you should either use a more specific XPath or use SelectNodes
and obtain the element located at the second index by means of an indexer like this:
Dim username =
htmldoc.DocumentNode.SelectNodes(
"//ul/li/b[text()='Username:']")(1).NextSibling.InnerHtml