Regexp get data from html page

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Andelys
    New Member
    • Aug 2007
    • 47

    Regexp get data from html page

    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
    Recognized Expert Moderator Expert
    • May 2007
    • 5388

    #2
    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

    Comment

    • Andelys
      New Member
      • Aug 2007
      • 47

      #3
      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?

      Comment

      • gits
        Recognized Expert Moderator Expert
        • May 2007
        • 5388

        #4
        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

        Comment

        • Andelys
          New Member
          • Aug 2007
          • 47

          #5
          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.

          Comment

          • gits
            Recognized Expert Moderator Expert
            • May 2007
            • 5388

            #6
            hmmm ... may be the following example helps:

            [CODE=javascript]var s = '</tr><tr><td>1135 </td><td>133</td><td>persons name</td><td>123</td></tr><tr><td>2342 3</td>';

            var id = '123';
            var re = new RegExp('.+' + id + '</td></tr>');

            var row = s.match(re)[0].match(/<tr>.+$/)[0];

            alert(row);[/CODE]
            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

            Comment

            Working...