Jump to content

What is the best way to parse an HTML file with javascript / jquery?

alanwunsche's Photo
Posted Oct 30 2010 08:10 PM
6689 Views

I have a URL which I've loaded into a variable as HTML. I need to be able to parse the data in the columns of the table and present the data in a different manner. The first step is parsing it but I can't seem to be find an easy way.

I'm trying regular expressions but there has to be a better way!

This is the js code so far:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<meta name="generator" content="TextMate http://macromates.com/">
<script type="text/javascript" charset="utf-8" src="jquery.js"></script>
</head>
<body>
<script type="text/javascript">

$.get("http://rankings.swimming.ca/index.php?page=athleteDetail&athleteId=17688150", function(data)
{
document.write(data);
var re = /class="swimtime"href=/; //the regular expressions
var foundPosition = data.search(re); / find the location of the regular expression
alert(foundPosition);
});

</script>
</body>
</html>

Appreciate the help!

Thanks,
Alan

Tags:
0 Subscribe


1 Reply

 : Oct 31 2010 01:11 PM
I've had some success...

I went ahead and parsed the html I received here:

<script type="text/javascript">
$.get("http://rankings.swimming.ca/index.php?page=athleteDetail&athleteId=17688150", function(data)
{
document.write(data);

[code here to parse the feed]

);
</script>
<body>
</body>


The issue I'm still having is that I want the data from within the parsing code to be available to other javascript code. How can I pass that data outside the function?

Thanks in advance!