0

I am working on to retrieve a table content(everything under <tbody>) from an URL to my page. It can be everything under <table> but remove <thread>...</thread>

I have search many references in this forum but not able to get the result I want.

The HTML structure as per the image(actual code too lengthy to paste here): [1]: https://i.stack.imgur.com/SgwM1.png

Appreciate if you can show me the light Orz

My sample code"

$url = 'https://xxxxxx.com/tracking/SUA000085003'; 

$ch = curl_init($url);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, true);
$cl = curl_exec($ch);

$dom = new DOMDocument();
$dom->loadHTML($cl);
$dom->validate();
$rows  = $dom->getElementsByTagName("tr");

foreach ($rows as $row) {
  $cells = $row -> getElementsByTagName('td');
  foreach ($cells as $cell) {
    print $cell->nodeValue; // print cells' content as 124578
    echo "<BR>";
  }
}
    

The result I got is:

https://xxxxxx.com/tracking/SUA000085003

15 May 202101:35:33
the goods left the warehouse in guangzhou
15 May 202101:35:33
arrived at sorting facility
14 May 202123:35:33
express operation is complete

The URL from the result is under <Table><thread>...</thread> I would like to remove this text entirely or only show the text after the last /, SUA000085003 is the example for this case.

  • 4
    Welcome. Please [edit] your question and paste the code you already have and where it fails – brombeer May 14 '21 at 13:55
  • 1
    Similar question here: https://stackoverflow.com/questions/8878381/extract-a-content-of-a-html-page-in-php If the table you want doesn't have an ID, you will have to go by offset. – Kenneth May 14 '21 at 19:52
  • @brombeer Thanks, I have added the coding and the sample result. – cedriccheah May 15 '21 at 04:51
  • @Kenneth I tried this but I got error from result. I dont use any IDE so I not sure what is the problem. – cedriccheah May 15 '21 at 04:52
  • @ced we never want images of textual information here. This is of no value to vision-impaired users and search engine crawlers. Please provide a minimal sample input, and your exact desired input from that sample input. I recommend that you use XPath with DOMDocument to target the desired data. – mickmackusa May 15 '21 at 05:10

0 Answers0