sorting data from scraped page

jlknauff

New member
Aug 25, 2008
237
1
0
I have a program that scrapes data from a particular page (data changes by the minute) and I've managed to get everything I need somewhat organized, and almost everything I don't need stripped out. There is still a bit I need to get rid of, and I want to load the remainder into an array.

Here is an example of how the data is structured:

some data here
some more data here
even more data here
final data here

other data here
some other data here
this other data here
that other data here

Each group will become an array - I can't figure out how to do that, and certain data will need to be removed before making the group an array (for example, let's say that I want to remove the second line in each group of data). If it will work better, I can break the data into a csv format.

Let me know if anyone has any ideas.
 


Considering I can't see the actual data from the scrape, would mean it's pretty hard to give you any kind of advice. Amature programmers probably shouldn't be scraping, or at least scraping in languages they are not well versed in IMHO.
 
Yeah.. could use a little more info. Is that the source of the data, or how it is displayed in a browser? If it is the source use
$lines = explode("\n", $data); or if not maybe
$lines = explode("<br/>", $data);

then...
[high=php]
$x = 0;
$key = 1;
foreach($lines as $val){
if($val == ""){
$key = 0;
if(isset($array[$x])){ // This makes sure it doesn't skip a number
$x++; // when finding empty lines.
}
if($key){
$array[$x][] = $val;
}
$key = 1;
}
[/high]

I think you get the idea.. explode the data into separate lines, then look for the empty lines and start a new array.
 
Or even easier...

<?php

$myText = '
some data here
some more data here
even more data here
final data here

other data here
some other data here
this other data here
that other data here
';

$arr = array();

$chunks = explode("\n\n",trim(str_replace("\r","",$myText)));

foreach($chunks as $bits) {
$arr[] = explode("\n", $bits);
}

print_r($arr);

?>
 
Or even easier...

<?php

$myText = '
some data here
some more data here
even more data here
final data here

other data here
some other data here
this other data here
that other data here
';

$arr = array();

$chunks = explode("\n\n",trim(str_replace("\r","",$myText)));

foreach($chunks as $bits) {
$arr[] = explode("\n", $bits);
}

print_r($arr);

?>

Seems to work perfectly, thanks!