I am trying to make a Greasemonkey userscript which it will display info from one website on another. I tried doing this with regular expressions, but got stuck on the match() syntax.
The page content is something like this:
<html><body>
<h1 class="pos-title">Fritz Paul</h1>
<div class="columns">
<div class="pos-column1">
<ul id="attributes">
... ...
</ul>
</div>
<div class="pos-column2">
<ul class="attributes">
... ...
</ul>
</div>
</div>
</body></html>
and I want to get only the:
<div class="columns">
<div class="pos-column1">
<ul id="attributes">
... ...
</ul>
</div>
<div class="pos-column2">
<ul class="attributes">
... ...
</ul>
</div>
</div>
I’ve tried code like:
attibutes = responseDetails.responseText.match(xxxx);
playerNotesContent.innerHTML = attibutes;
I tried a lot of .match(...) examples that I found in this site but I can’t make it work.
As others have said, never attempt to parse HTML with regular expressions. Use DOM parsing instead.
The question is not clear, but it appears that you are fetching a page via AJAX and attempting to parse it, right? Also, do you really want all the markup inside each
<div class="columns">or just specific bits of text?Here is the general approach for Greasemonkey. It uses jQuery to make DOM parsing easier.
Updated based on OP’s comments and posted script. :