Jump to content

php curl read <td> and <tr> tags


the_ut_tick

Recommended Posts

Hi,

 

  I am reading in a government page from the House of Reps site and I want to pull some data from the huge tables they have there concerning bills and amendments.  It occured to me that if I could break up the string that comes in from Curl with the <td> and <tr> tags within the source, then my life will be complete.  When I search for those tags though, they aren't found.  It seems that when I search the string return by cURL, it doesn't include these things.  Any ideas?

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/49982-php-curl-read-and-tags/
Share on other sites

<?php

function textbetweenarray($s1,$s2,$s){
  $myarray=array();
  $s1=strtolower($s1);
  $s2=strtolower($s2);
  $L1=strlen($s1);
  $L2=strlen($s2);
  $scheck=strtolower($s);

  do{
  $pos1 = strpos($scheck,$s1);
  if($pos1!==false){
    $pos2 = strpos(substr($scheck,$pos1+$L1),$s2);
    if($pos2!==false){
      $myarray[]=substr($s,$pos1+$L1,$pos2);
      $s=substr($s,$pos1+$L1+$pos2+$L2);
      $scheck=strtolower($s);
      }
        }
  } while (($pos1!==false)and($pos2!==false));
return $myarray;
}

$content = file_get_contents("page.html");

$trs = textbetweenarray("<tr>", "</tr>", $content);

foreach($trs as $tr) {
echo $tr;
}

?>

 

Sorry to bump the thread, new here and thought I'd like to help!

 

That code above stores the contents of each row in $trs and outputs each one. Can be adapted to then split each row into a <td> and so on..

 

cURL should pick up the source code, which code are you using to access the page?

 

Hope that helps :)

 

Chigley

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.