Actually I’ve parsed a website using htmlparser and I would like to find a specific value inside the parsed object, for example, a string “$199”, and keep tracking that element(by periodic parsing) to see the value is still “$199” or has changed.
And after some painful stupid searching using my eyes, I found the that string is located at somewhere like this:
price = handler.dom[3].children[3].children[3].children[5].children[1].
children[3].children[3].children[5].children[0].children[0].raw;
So I’d like to know whether there are methods which are less painful? Thanks!
A tree based recursive search would probably be easiest to get the node you’re interested in.
I’ve not used
htmlparserand the documentation seems a little thin, so this is just an example to get you started and is not tested:Call
getElement(handler.dom[3],'$199')and it’ll go through all the children recursively until it finds an element without anchildrenand then compares it’s raw value with ‘$199’. Note this is a straight comparison, you might want to swap this for a regexp or similar?