query for xpath text after specific row value

kippemagmerse

New Member
LanguageJavascript: Using the following code to retrieve the text content from a web page using xpath.\[code\]findNode: function(xpath, doc) { var nodes=System.findNodes(xpath, doc); if (!nodes) return null; return (nodes[0]);},findNodes: function(xpath, doc) { if (!doc) { doc=document; } var nodes=[]; if(xpath.indexOf('/') == 0) xpath = '.'+xpath; //this is a chrome fix - needs a .// for xpath where as firefox can fucntion without it. firefox sitll works with .// var findQ = document.evaluate(xpath, doc, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null); if (findQ.snapshotLength===0) return null; for (var i=0; i<findQ.snapshotLength; i++) { nodes.push(findQ.snapshotItem(i)); } return nodes;},\[/code\]\[code\]<table border="0" cellpadding="2" cellspacing="0"> <tr> <td colspan="10"><b>Area One Set</b></td> </tr> <tr> <td><b>Type:</b></td> <td colspan="4" width="50%">A</td> <td><b>Data1:</b></td> <td colspan="4" width="50%">1</td> </tr> <tr> <td><b>Data2:</b></td> <td>200</td> <td><b>Data3:</b></td> <td>100</td> </tr> <tr> <td colspan="10"><b>Area Two Variable</b></td> </tr> <tr> <td><nobr><b>Data2:</b></nobr></td> <td>1</td> <td><nobr>&nbsp;-&nbsp;</nobr></td> <td>25</td> <td width="50%"></td> <td colspan="4"></td> </tr> <tr> <td><nobr><b>Data3:</b></nobr></td> <td>50</td> <td><nobr>&nbsp;-&nbsp;</nobr></td> <td>75</td> <td width="50%"></td> <td colspan="4"></td> </tr> <tr> <td colspan="10"><b>Area Four Set</b></td> </tr> <tr> <td><b>Data2:</b></td> <td colspan="3">0</td> <td width="50%"></td> <td><b>Data3:</b></td> <td colspan="3">0</td> <td width="50%"></td> </tr>\[/code\] Method for retrieving the html I need is a call to\[code\] var Data1Text = System.findNode("//tr[td/b[.='Area Four Set']]/following-sibling::tr[2]/td[2]", doc).textContent;\[/code\]This has worked for me so far, but now I need to grab the data from the 'Area Two' that is variable as to what data fields (Data1, Data2, Data3, etc) will be there depending on the item I am grabbing data from. The text matches up to three areas at any given time, Area One and Area Four all the time and Area Two sometimes.ObjectiveI need help tailoring my findnode query to grab the Data1, Data2, etc. values from the Area Two when they are present in the table. If the table row contains the Area Set Two name, I need the next table row data. Thanks, I couldn't find anything similar that has been answered.
 
Back
Top