Connecting Tech Pros Worldwide Forums | Help | Site Map

Regexp get data from html page

Member
 
Join Date: Aug 2007
Posts: 45
#1: Apr 19 '08
Hey

I have to get some data from a html page into an other page. I know how to get the data by a simple AJAX request, but I don't know to find the data.

The data i need to find is in a table, and there are about 100 rows in it. I only need to get one. The only thing i got is the persons ID.
The row looks like this:
[HTML]
<tr class="Lyscell">
<td>48</td>
<td>29</td>
<td>Persons name</td>
<td>Persons ID</td>
</tr>
[/HTML]


I was thinking of a regexp or something, but i'm open for all other ways to find the data in the html page :)

gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,135
#2: Apr 19 '08

re: Regexp get data from html page


hmmm ... i'm not quite sure what you mean? basicly you want to retrieve the last cell in every row and get its text that is a person's ID? am I right?

kind regards
Member
 
Join Date: Aug 2007
Posts: 45
#3: Apr 19 '08

re: Regexp get data from html page


No, that not what i want. Sorry for the bad explanation.'

I have the person id, and i want the get the whole row that its in.

Fx i have the person id: 123 and the table looks like this:
[HTML]
<table>
<tr>
<td>115</td>
<td>153</td>
<td>persons name</td>
<td>persons ID</td>
</tr>
<tr>
<td>1135</td>
<td>133</td>
<td>persons name</td>
<td>123</td>
</tr>
<tr>
<td>23423</td>
<td>133</td>
<td>persons name</td>
<td>persons ID</td>
</tr>
</table>
[/HTML]

How do i get that row?
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,135
#4: Apr 19 '08

re: Regexp get data from html page


i see ... could there be more then one row with that person id? are you using responseText or responseXML? do you need to display the entire table or just need the retrieved row from the response?

kind regards
Member
 
Join Date: Aug 2007
Posts: 45
#5: Apr 19 '08

re: Regexp get data from html page


No only one person have that id.
I'm using reponseText.
I just need to get that one row were the ID is in. If it helps, i can also use the name for finding the row.
gits's Avatar
Moderator
 
Join Date: May 2007
Location: Munich, Germany
Posts: 4,135
#6: Apr 22 '08

re: Regexp get data from html page


hmmm ... may be the following example helps:

Expand|Select|Wrap|Line Numbers
  1. var s = '</tr><tr><td>1135</td><td>133</td><td>persons name</td><td>123</td></tr><tr><td>23423</td>';
  2.  
  3. var id = '123';
  4. var re = new RegExp('.+' + id + '</td></tr>');
  5.  
  6. var row = s.match(re)[0].match(/<tr>.+$/)[0];
  7.  
  8. alert(row);
but the best way would be to just retrieve the needed data from the database ... instead of the entire table ... or is this not an option?

kind regards
Reply


Similar JavaScript / Ajax / DHTML bytes