1
  1. I have gone to the db and created an array of url's.
  2. Then I go through the array and use xpath to tell me how many links there are per url.
  3. This is where my head hurts.

I have a count for each url of the no of objects in each url. So I'm now trying to collect each of the nodevalues from part 2.

I'm obviously doing something wrong but need some guidence please

 $items = array(); $query = "SELECT * FROM `urls`"; if( $result = mysqli_query($sql,$query)); { // Return the number of rows in result set $rowcount=mysqli_num_rows($result); while ($row = $result->fetch_assoc()) { $items[] = $row; } } echo '<pre>'; print_r($items); // $product = array(); echo $rowcount; for ($x=0; $x<$rowcount; $x++){ $scrapeurl[$x] = $items[$x][url]; echo $scrapeurl[$x]; $xpath[$x] = new XPATH($scrapeurl[$x]); $urls[$x] = $xpath[$x]->query("//div[@class='infodata']/strong/a[contains(@id,'test_title')]/@href"); $count[$x] = $urls[$x]->length; $data = array(); for ($i=0; $i<$count[$x]; $i++){ $data[$i]['url'] = $urls[$x]->item($i)->nodeValue; $data[] = $data[$i]['url']; } echo '<pre>'; print_r($data); 
1
  • Can you post the output of this script, please, so that we can see the content of $items? Commented Jul 28, 2015 at 13:07

1 Answer 1

1

A bit late apologies but resolved the issue. Maybe too tired but came down to a couple of issues.

  1. Don't always believe what the browser renders in the HTML. Look at the source! I found that tbody as an example is filled into HTML by Firefox at least in reality the source was different so I was never going to hit the right node.

  2. looping within loops - to remember when in a loop sometimes you have to loop again to drill down to the right result......

    $data = array(); foreach($urls as $node){ foreach($node->childNodes as $child) { $data[] = array($child->nodeName => $child->nodeValue); } } $data = new RecursiveIteratorIterator(new RecursiveArrayIterator($data)); $data = iterator_to_array($data,false); 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.