javascript - How do I retrieve text from an embedded script using casperjs? -


the html element is

<script> window.sawxmlislandidclientstatexml="<nqw xmlns:saw=\x22com.siebel.analytics.web/report/v1.1\x22 xmlns:xsi=\x22http://www.w3.org/2001/xmlschema-instance\x22 xmlns:sawst=\x22com.siebel.analytics.web/state/v1\x22>\u003csawst:clientstate>\u003csawst:stateref>\u003csawst:envstate xmlns:sawst=\"com.siebel.analytics.web/state/v1\" xmlns:xsi=\"http://www.w3.org/2001/xmlschema-instance\" xmlversion=\"200811100\">\u003csawst:container cid=\"d:dashboard\" xsi:type=\"sawst:toplevelstatecontainer\">\u003csawst:container cid=\"p:mco0pb0nob7sqjvg\" xsi:type=\"sawst:page\">\u003csawst:container cid=\"s:42263r43nih80fd1\" xsi:type=\"sawst:section\" rendered=\"true\">\u003csawst:container cid=\"g:c452lvndqssjqa45\" xsi:type=\"sawst:dashprompt\" links=\"-\" promptautocompletestate=\"off\"/>\u003c/sawst:container>\u003csawst:container cid=\"r:q4g2fiisnvk4nusv\" xsi:type=\"sawst:report\" links=\"fd\" defaultview=\"compoundview!1\" searchid=\"fvup02s9lt0o6urkplv4pqa5ri\" folder=\"/shared/sales\" itemname=\"all sales , inventory data\"/>\u003csawst:container cid=\"f:dpstate\" xsi:type=\"sawst:dashpromptstate\" statepoolid=\"ih2bj24l46bkgt558qsef04jeq\"/>\u003csawst:container cid=\"s:b0003tc6gnahvsfq\" xsi:type=\"sawst:section\" rendered=\"true\"/>\u003csawst:container cid=\"s:c5j314uterctfb08\" xsi:type=\"sawst:section\" rendered=\"true\"/>\u003c/sawst:container>\u003c/sawst:container>\u003c/sawst:envstate>\u003c/sawst:stateref>\u003csawst:reportxmlrefferedto>\u003cref statepath=\"d:dashboard~p:mco0pb0nob7sqjvg~r:q4g2fiisnvk4nusv\" searchid=\"8oh8erup3kcqav10ukp36jaof2\">\u003c/ref>\u003c/sawst:reportxmlrefferedto>\u003c/sawst:clientstate></nqw>"; </script> 

i want retrieve string ih2bj24l46bkgt558qsef04jeq under identifier statepoolid script section. how find script in html , string using casperjs?

accessing window.sawxmlislandidclientstatexml:

this script element in page adds variable global scope, can access through casper.evaluate:

casper.then(function(){     var sawxmlislandidclientstatexml = casper.evaluate(function(){         return window.sawxmlislandidclientstatexml;     });     // todo: }); 

doing sawxmlislandidclientstatexml:

you could

  • do simple string operations split string in more manageable pieces can parsed easier yourself,
  • write regex matcher find specific detail you're looking for, or
  • use domparser parse string xml , use either yourparseddocument.queryselector or yourparseddocument.evaluate locate element through css selectors or xpath expressions, respectively.

Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -