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
https://forums.phpfreaks.com/topic/80294-screen-scrape/
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
https://forums.phpfreaks.com/topic/80294-screen-scrape/#findComment-410148
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
https://forums.phpfreaks.com/topic/80294-screen-scrape/#findComment-410171
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.