parsing html text with regex in javascript? -
i realize html can not parsed regex. however, have string source code typical amazon web page.
<script type="text/javascript"> p.when("a", "jquery").execute(function(a, $) { var pagestate = a.state('ftpagestate'); if (typeof pagestate === 'undefined') { pagestate = {}; } if (pagestate["fast-track-message"]) { pagestate["fast-track-message"].stoptimer(); } <li> 48 pages</li> pagestate["fast-track-message"] = new fasttrackcountdown(20710,"fast-track-message"); a.state('ftpagestate', pagestate); }); </script>
i want grab 48. every number followed pages</li>
how can match this?
attempt
var string_tester = string(datastuff.html()); var regex_tester = string_tester.match(/\d+ pages<\/li>/);
if know in list element, try this: (<li>\s*)([0-9]+)(\s*pages\s*</li>)
(48 in $2
. however, won't accommodate number formatting. should generic enough: (<li>\s*)([0-9,\.\-\(\)]+)(\s*pages\s*</li>)
. should note amazon has seller , publisher api might provide more stable route pursue depending on use case.
edit: checked few amazon pages see if there better approach getting want , noticed pages checked there no number, this:
<script type="text/javascript"> p.when("a", "jquery").execute(function(a, $) { var pagestate = a.state('ftpagestate'); if (typeof pagestate === 'undefined') { pagestate = {}; } if (pagestate["fast-track-message"]) { pagestate["fast-track-message"].stoptimer(); } pagestate["fast-track-message"] = new fasttrackcountdown(57592,"fast-track-message"); a.state('ftpagestate', pagestate); }); </script>
i don't know doing, wanted mention in case invalidates assumption have made.
Comments
Post a Comment