You are viewing our Forum Archives. To view or take place in current topics click here.
[VB] Get each element inside of an element?
Posted:

[VB] Get each element inside of an element?Posted:

Z61
  • V5 Launch
Status: Offline
Joined: Apr 16, 201014Year Member
Posts: 4,309
Reputation Power: 179
Status: Offline
Joined: Apr 16, 201014Year Member
Posts: 4,309
Reputation Power: 179
I want to be able get all divs inside of a specific div via its ID.
Example:

<div id="outer">
  <div>Inner</div>
</div>

I want to be able to get the div that contains inner.
#2. Posted:
CoNdEmR
  • Shoutbox Hero
Status: Offline
Joined: Apr 29, 200915Year Member
Posts: 4,420
Reputation Power: 1211
Status: Offline
Joined: Apr 29, 200915Year Member
Posts: 4,420
Reputation Power: 1211
I'm unsure as to what it is you exactly want, however i'm going to make a stab at it and say it's this your looking for. If not you can try this.


<div class="content">
  <div id="inner">
  Anything within this id will also relate to the div class.
  </div>
</div>


#3. Posted:
Z61
  • V5 Launch
Status: Offline
Joined: Apr 16, 201014Year Member
Posts: 4,309
Reputation Power: 179
Status: Offline
Joined: Apr 16, 201014Year Member
Posts: 4,309
Reputation Power: 179
CoNdEmR wrote I'm unsure as to what it is you exactly want, however i'm going to make a stab at it and say it's this your looking for. If not you can try this.


<div class="content">
  <div id="inner">
  Anything within this id will also relate to the div class.
  </div>
</div>



Im trying to load this in VB.
#4. Posted:
Imp
  • Retired Staff
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Heres a neat way to extract Data from HTML using XPath.

Using this HTML as an example

<html>
<body>

<div id="outer">
  <div>Inner</div>
  <div>Inner2</div>
  <div>Inner3</div>
  <div>Inner4</div>
</div>
<div id="blah">
  <div>blah1</div>
  <div>blah2</div>
  <div>blah3</div>
  <div>blah4</div>
</div>
</body>
</html>


Running this code will pull all the text in the Inner DIVs and display in the console


Dim xpathDoc As XPathDocument
Dim xmlNav As XPathNavigator
Dim xmlNI As XPathNodeIterator
Dim DivDetail() As String

xpathDoc = New XPathDocument("c:\test.html")
xmlNav = xpathDoc.CreateNavigator()
xmlNI = xmlNav.Select("/html/body/div[@id=""outer""]")

xmlNI.MoveNext()

DivDetail = Split(Replace(xmlNI.Current.InnerXml, "</div>", ""), "<div>")
For tmpcount = 0 To UBound(DivDetail)
     System.Console.WriteLine(DivDetail(tmpcount))
Next



xmlNav.Select("/html/body/div[@id=""outer""]")

This is the important line, changing this will allow you to quicklly search through any HTML document, or XML, for the information you require.
#5. Posted:
skate101
  • Junior Member
Status: Offline
Joined: Apr 19, 200915Year Member
Posts: 65
Reputation Power: 2
Status: Offline
Joined: Apr 19, 200915Year Member
Posts: 65
Reputation Power: 2
okay maybe the string "inner" is a innertext.

if that is the case you can try:

LABEL1.TEXT = WebBrowser1.Document.GetElementById("IDGOESHERE").innertext
#6. Posted:
Imp
  • Retired Staff
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
skate101 wrote okay maybe the string "inner" is a innertext.

if that is the case you can try:

LABEL1.TEXT = WebBrowser1.Document.GetElementById("IDGOESHERE").innertext


That only works for the Innertext for the DIV with a specific ID, he wants to extract all DIVs inside the DIV with the ID he knows... if that makes sense
#7. Posted:
skate101
  • Junior Member
Status: Offline
Joined: Apr 19, 200915Year Member
Posts: 65
Reputation Power: 2
Status: Offline
Joined: Apr 19, 200915Year Member
Posts: 65
Reputation Power: 2
Imp wrote
skate101 wrote okay maybe the string "inner" is a innertext.

if that is the case you can try:

LABEL1.TEXT = WebBrowser1.Document.GetElementById("IDGOESHERE").innertext


That only works for the Innertext for the DIV with a specific ID, he wants to extract all DIVs inside the DIV with the ID he knows... if that makes sense


had to read it like 5 times lol. hmm but he wants all the inner texts? of all the divs with 1 element id?

dude i'm confused. he could try getting it by tagname if anything
#8. Posted:
Imp
  • Retired Staff
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
Status: Offline
Joined: Jan 01, 201113Year Member
Posts: 1,957
Reputation Power: 401
skate101 wrote
Imp wrote
skate101 wrote okay maybe the string "inner" is a innertext.

if that is the case you can try:

LABEL1.TEXT = WebBrowser1.Document.GetElementById("IDGOESHERE").innertext


That only works for the Innertext for the DIV with a specific ID, he wants to extract all DIVs inside the DIV with the ID he knows... if that makes sense


had to read it like 5 times lol. hmm but he wants all the inner texts? of all the divs with 1 element id?

dude i'm confused. he could try getting it by tagname if anything


IKR lol, thats why its was easier to use XPath then he can filter the HTML down, it works well
#9. Posted:
Bighair
  • Powerhouse
Status: Offline
Joined: Sep 26, 201014Year Member
Posts: 401
Reputation Power: 17
Status: Offline
Joined: Sep 26, 201014Year Member
Posts: 401
Reputation Power: 17
Use regex? thats what i use when i'm pharsing HTML
Jump to:
You are viewing our Forum Archives. To view or take place in current topics click here.