Navigating the DOM with parentNode, previousSibling,nextSibling, firstChild, and lastChild

Navigating the DOMSometimes it is not convenient to grab the specific element you want while you’re scraping a web page.  In this tutorial I walk through how to use parentNode, previousSibling,nextSibling,firstChild and lastChild.

Here is the script I worked through to Navigating the DOM

#SingleInstance,Force
;**************************************
pwb:=WBGet()
;~ https://the-automator.com
;~ ParentNode, nextSibling, PreviousSibling,FirstChild,LastChild

MsgBox % pwb.document.getElementbyID("prime_nav").FirstChild.InnerText
MsgBox % pwb.document.getElementsbyTagname("li")[0].InnerText "`r"
  . "next: " pwb.document.getElementsbyTagname("li")[0].nextSibling.InnerText "`r"
  . "third: "pwb.document.getElementsbyTagname("li")[0].nextSibling.nextSibling.InnerText
MsgBox % pwb.document.getElementsbyTagname("li")[0].ParentNode.ParentNode.InnerText 

 

Navigating the DOM

Comments are closed.