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
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>';
}
}

Link to comment
Share on other sites

<?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>';
}
}?>

Link to comment
Share on other sites

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>';
}
}?>

Link to comment
Share on other sites

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>';
}
}?>

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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