Jump to content

[SOLVED] Screen Scrape


ainoy31

Recommended Posts

Hello-

 

Here is the data:

<TR>

<TD ALIGN="LEFT">

<SMALL><B>Pickup Date:</B> 11/14/2007</SMALL><BR><SMALL><B>Delivery Date:</B> 11/15/2007</SMALL><BR><SMALL><B>Delivery Status:</B> Delivered</SMALL><BR><SMALL><B>Delivery Time:</B> 11:29</SMALL><BR>

<TD>

</TR>

 

I need to get the Delivery Status: out.  Here is what I have tried:

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

{

if(stristr($line, '<B>Delivery Status:</B>'))

{

preg_match('#(Delivery Status):.([^"]*?)#is', $data, $matches);

print_r($matches);

}

}

 

Any suggestion is much appreciated.  AM

 

 

Link to comment
https://forums.phpfreaks.com/topic/79563-solved-screen-scrape/
Share on other sites

<pre>
<?php
$data = <<<DATA
<TR>
<TD ALIGN="LEFT">
<SMALL><B>Pickup Date:</B> 11/14/2007</SMALL><BR><SMALL><B>Delivery Date:</B> 11/15/2007</SMALL><BR><SMALL><B>Delivery Status:</B> Delivered</SMALL><BR><SMALL><B>Delivery Time:</B> 11:29</SMALL><BR>
<TD>
</TR>
DATA;

preg_match('%(?<=Delivery Status:</B>)\s*([^<]+)%', $data, $matches);
array_shift($matches);
print_r($matches);
?>
</pre>

Link to comment
https://forums.phpfreaks.com/topic/79563-solved-screen-scrape/#findComment-402970
Share on other sites

Here is the solution:

 

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

{

if(stristr($line, 'Pickup Date:'))

{

$pattern = "/([0-9]{1,2})\/([0-9]{1,2})\/([0-9]{1,4})/";

preg_match($pattern, $line, $matches);

$pu_date = date("Y-m-d", strtotime($matches[0]));   

}

if(stristr($line, 'Delivery Date:'))

{

preg_match_all('#(Delivery Date):.*?(\d{2}/\d{2}/\d{4})#is', $data, $matches, PREG_SET_ORDER);

$deliv_date = date("Y-m-d", strtotime($matches[0][2]));

$status = 'Delivered';

$delivered = true;

 

if($matches[0][2] == '')

{

preg_match('%(?<=Delivery Status:</B>)\s*([^<]+)%', $data, $matches);

array_shift($matches);

$status = $matches[0];

$delivered = false;

$deliv_date = null;

}

}

Link to comment
https://forums.phpfreaks.com/topic/79563-solved-screen-scrape/#findComment-402982
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.