1

is there a way to cut of the query and return back the results.. preset time to take to get all images from the given url .. i.e. query half of the webpage ? or job time not greater than 5 seconds, so therefore, it will get everything it can in 5 seconds.....

$xpath = new DOMXPath( $htmlget);
       $nodelist = $xpath->query( "//img/@src" );
dean jase
  • 1,151
  • 5
  • 23
  • 37
  • Good question, +1. Yes, very roughly you could substitute the evaluation of one single XPath expression with separate evaluation of the items of a *sequence* of individual XPath expressions. – Dimitre Novatchev Sep 14 '11 at 12:34

1 Answers1

0

You can evaluate separately any of the following XPath expressions one by one, and stop this process whenever a timer expires or other criterion is satisfied:

(//img/@src)[1]
(//img/@src)[2]
(//img/@src)[3]
...............
(//img/@src)[$N]

This can probably be speeded-up by chunking:

(//img/@src)[position() < 100]
(//img/@src)[position() >= 100 and position() < 200]
...............
(//img/@src)[position() >= 100*$N and position() < 200*$N]
Dimitre Novatchev
  • 230,371
  • 26
  • 281
  • 409
  • wherre shall i put this position? if i want to get only the first image it finds, what shall i do? $xpath->query( "(//img/@src)[1]" ); ? – dean jase Sep 14 '11 at 20:55
  • @dean_jase: Yes, seems like this -- I don't know your particular XPath engine API and have confidence that you know how to evaluate XPath expressions with it. – Dimitre Novatchev Sep 14 '11 at 21:34