0

I am trying to find specific element from the pages below:

$links=array(
"https://www.computers.com/l_bg/?m=7&i=587609", 
"https://www.computers.com/l_bg/?m=7&i=587610", 
"https://www.computers.com/l_bg/?m=7&i=587607", 
"https://www.computers.com/l_bg/?m=7&i=587502"
); 


foreach($links as $link){
$newhtml = new simple_html_dom();
$newhtml->load_file($link);

foreach($newhtml->find('table.fpt > td.name') as $price){
echo $price=$price->innertext;
    }
}

but the $price is empty.. The strange thing is that if I change the code to this:

$newhtml = new simple_html_dom();

$newhtml->load_file('https://www.computers.com/l_bg/?m=7&i=587609');
foreach($newhtml->find('table.fpt > td.name') as $price){
echo $price=$price->innertext;
}

the code works.. Why if I manual put the url it works, but when is in loop it doesn't? Can you please tell me what is wrong and how to find it?

3
  • Try using the hard-coded link (as in your 2nd example) but put it in a loop that goes through 4-5 times for ($i=0; $i < 4; $i++) { ... } to see if it's some kind of timing issue. Commented Apr 2, 2015 at 18:25
  • I will test it now but same time to share what else I discovered: if I test the headers here webconfs.com/http-header-check.php with one of the urls jarcomputers.com/l_bg/?m=7&i=587609 I am getting HTTP/1.1 400 Bad Request => is this connected to this? Commented Apr 2, 2015 at 18:29
  • Yes, that could very well be it. Perhaps your jarcomputers.com is not returning the pages consistently. Commented Apr 2, 2015 at 18:37

1 Answer 1

1

The problem seems to be encoding problem. If the url has & its been transformed to &amp; which must be replaced with & in order to work.. Thank you anyway for your help !

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.