Jump to content

create html parser loop through


dflow

Recommended Posts

What do you mean? You need an array of products and product links which you crawl using whatever method. You then use a foreach() loop to loop through each product, then use the product link to parse the product link page.

 

$products = array('linkpage1.html','linkpage2.html');

 

foreach($products as $product){

 

  parse($product);

 

}

ok got you

now how can i explode a link structured"product/product_1.htm"

from the array created?

i got all the links on the page and want only the specific ones

 

for example:

foreach($html->find('a') as $e) {
    echo $arraylinks[] = $e->href . '<br>';

}
$linkChunks = explode("product/", $apartmentpage_linkr);


As a test:

 

foreach ($arraylinks as $link) {
   $category = basename(dirname($link));
   $page = basename($link);
   
   if ($category == "apartments") {
      echo  $page.'<br />';
   }
}

 

works thanks

what was the problem before?

 

i got the results but with that error

As a test:

 

foreach ($arraylinks as $link) {
   $category = basename(dirname($link));
   $page = basename($link);
   
   if ($category == "apartments") {
      echo  $page.'<br />';
   }
}

 

actually now ill need the results as an array and to loop through each link

Something like this will give all the results in an array:

 

foreach ($arraylinks as $link) {
   $category = basename(dirname($link));
   $page = basename($link);
   
   $links[$category][] = $page;
}

Then you can do something like this:

 

foreach($links['apartments'] as $page) {
   echo $page;
}

or:

 

foreach($links as $category => $page) {
   echo $category . ': ' . $page;
}

 

ok

im getting the links but i have 3 results of each how can i limit it to 1 result per link

 

now im trying to put things together and making a mess

i want to loop through each link and get the html contents parsed

 

 

<?php
// example of how to use basic selector to retrieve HTML contents
include('../simple_html_dom.php');

// get DOM from URL or file
$html = file_get_html('http://www.example.com/ViewAllApartments.aspx');




   
   



// find all links
foreach($html->find('a') as $e) {
     $arraylinks[] = $e->href . '<br>';

}






foreach ($arraylinks as $link) {
   $category = basename(dirname($link));
   $page = basename($link);
   
   if ($category == "apartments") 
{
{
   $url="http://www.example.com/apartments/";
      echo  $page.'<br />';
  echo  $url.$page.'<br />';
   }
}

foreach($links['apartments'] as $page) {
   $phtml = file_get_html($url.$page);


foreach($phtml->find('span[id=apartmentname]') as $apartmentname)
    echo $apartmentname->plaintext.'<br><br>';
}




?>

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.