Jump to content

Screen Scrape


ainoy31

Recommended Posts

Hello-

 

I need help with getting data off the screen.  Here is the data:

<tr>

<td class="text" width='90' align='right' bgcolor='#f5deb3'>Pickup Date:</td>

<td class="text" width='90' bgcolor='#f5f5dc'><b>12/04/07</b></td>

<td class="text" width='90' align='right' bgcolor='#f5deb3'>Del Date/Time:</td>

<td class="text" width='90' bgcolor='#f5f5dc'><b>* in route *</b></td>

</tr>

 

I need to get the status of the Del Date/Time field out which is * in route * but it could be a date later on.  Here is what I have tried.

 

foreach(explode("\n",$data) as $line)

{

if(stristr($line, 'Del Date/Time:'))

{

preg_match('%(?<=Del Date/Time:</td>)\s*([^<]+)%', $data, $matches);

print_r($matches);

}

}

 

Much appreciation.

Link to comment
Share on other sites

I need help with getting data

Care to explain more specifically how we can help you?

 

What is your problem and what is the output of $matches ?

Posting this information would certainly help see where your problem is, of course you'll have to state what your problem is first. :)

Link to comment
Share on other sites

1: <tr>

2: <td class="text" width='90' align='right' bgcolor='#f5deb3'>Pickup Date:</td>

3: <td class="text" width='90' bgcolor='#f5f5dc'><b>12/04/07</b></td>

4: <td class="text" width='90' align='right' bgcolor='#f5deb3'>Del Date/Time:</td>

5: <td class="text" width='90' bgcolor='#f5f5dc'><b>* in route *</b></td>

6: </tr>

 

foreach(explode("\n",$data) as $line)

{

if(stristr($line, 'Del Date/Time:'))

{

preg_match('%(?<=Del Date/Time:</td>)\s*([^<]+)%', $data, $matches);

print_r($matches);

}

}

 

 

Your IF condition (in bold above) will only be positive and come into play at line 4:.

 

Since this is inside a foreach loop, line 4 is the only line that exists, therefore your preg_match will never find the *in route* which is on line 5.

Link to comment
Share on other sites

<?php
$str = <<<EOD
<tr>
<td class="text" width='90' align='right' bgcolor='#f5deb3'>Pickup Date:</td>
<td class="text" width='90' bgcolor='#f5f5dc'>12/04/07</td>
<td class="text" width='90' align='right' bgcolor='#f5deb3'>Del Date/Time:</td> <td class="text" width='90' bgcolor='#f5f5dc'>* in route *</td>
</tr>
EOD;
$pat = '~Del Date/Time:\</td\> \<td class="text" width=\'90\' bgcolor=\'#f5f5dc\'\>((??!\</td\>).)+)\</td\>~s';
preg_match_all($pat, $str, $out);
print_r($out);
?>

 

this works as long as:

Del Date/Time:</td> <td

                            ^

                    end of del/date td tag and next td tag are seperated by 1 space

 

you can change the pattern to suit however else it may be seperated, like with a line break, depending on your data, a good rule of thumb is just to remove all line breaks period from the haystack, and then search data, but it can be done without that as well using $ and ^ or s modifiers..

it really depends how static or not this data you are searching through is coming in.... so you must know details/specifics to make such a decision

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.