Jump to content

loop through different websites:confused:


dflow

Recommended Posts

i have an array of website links i want to loop through each and get a certain html id foreach

 

whats wrong with what i did here? :confused: :confused:

foreach($links as $page) {
   $phtml = file_get_html($page);

// find all td tags with attribite align=center
foreach($phtml->find('span[id=name]') as $name)
    echo $name->plaintext.'<br><br>';
}

Link to comment
https://forums.phpfreaks.com/topic/221982-loop-through-different-websitesconfused/
Share on other sites

You haven't enclosed the second foreach statement in curly brackets.

 

It should be:

 

foreach($links as $page) {
   $phtml = file_get_html($page);

// find all td tags with attribite align=center
foreach($phtml->find('span[id=name]') as $name){
    echo $name->plaintext.'<br><br>';
}
}

<?php
// example of how to use basic selector to retrieve HTML contents
include('simple_html_dom.php');
$links=array("http://www.example.com/page1.htm","
http://www.example.com/page2.htm")



foreach($links as $page) {
   $phtml = file_get_html($page);

// find all td tags with attribite align=center
foreach($phtml->find('span[id=name]') as $name){
    echo $name->plaintext.'<br><br>';
}
}?>

Was no semicolon after links array

 

<?php
// example of how to use basic selector to retrieve HTML contents
include('simple_html_dom.php');
$links=array("http://www.example.com/page1.htm","
http://www.example.com/page2.htm");



foreach($links as $page) {
   $phtml = file_get_html($page);

// find all td tags with attribite align=center
foreach($phtml->find('span[id=name]') as $name){
    echo $name->plaintext.'<br><br>';
}
}?>

thanks

now i run the whole script and their are 2 problems

1. i get still get non unique links(3 of a kind)

2. error:

Notice: Undefined variable: links in parser.php on line 41

 

Warning: Invalid argument supplied for foreach() in parser.php on line 41

<?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/AllApartments.aspx');



//foreach($html->find('td[class=stableline1]') as $f) {
  // $arrayf[] = $f->innertext;
   
   
//}


// find all link
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);

// find all td tags with attribite 
foreach($phtml->find('span[id=lblCodiceAppartamento]') as $name){
    echo $name->plaintext.'<br><br>';
}
}?>

  Quote

thanks

now i run the whole script and their are 2 problems

1. i get still get non unique links(3 of a kind)

2. error:

Notice: Undefined variable: links in parser.php on line 41

 

Warning: Invalid argument supplied for foreach() in parser.php on line 41

<?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/AllApartments.aspx');



//foreach($html->find('td[class=stableline1]') as $f) {
  // $arrayf[] = $f->innertext;
   
   
//}


// find all link
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 />';
   }
}
$links=array();
foreach($links['apartments'] as $page) {
   $phtml = file_get_html($url.$page);

// find all td tags with attribite 
foreach($phtml->find('span[id=lblCodiceAppartamento]') as $name){
    echo $name->plaintext.'<br><br>';
}
}?>

 

now i get a memory issue although i set the php.ini to maximum

when looping through 20 different urls

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 700 bytes) in/simplehtmldom/simple_html_dom.php on line 829

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.