0

I'm trying to get data from HTML using DOM. I can get some data, but can't figure out how to get the rest. Here is an image highlighting the data I want.

https://i.sstatic.net/7WmwS.png

here is the code itself

http://pastebin.com/Re8qEivv

and here my PHP code

$html = file_get_contents('result.html');
$dom = new DOMDocument;
$dom->loadHTML($html);
$tr = $dom->getElementsByTagName('tr');

foreach ($tr as $row){

    $td = $row->getElementsByTagName('td');
    $td1 = $td->item(1);
    $td2 = $td->item(2);

    foreach ($td1->childNodes as $node){
        $title = $node->textContent;      
    }

    foreach ($td2->childNodes as $node){
        $type = $node->textContent;
    }

}

2 Answers 2

2

Figured it out

$html = file_get_contents('result.html');
$dom = new DOMDocument;
$dom->loadHTML($html);
$tr = $dom->getElementsByTagName('tr');

foreach ($tr as $row){

    $td = $row->getElementsByTagName('td');
    $td1 = $td->item(1);
    $td2 = $td->item(2);

    $title = $td1->childNodes->item(0)->textContent;
    $firstURL = $td1->getElementsByTagName('a')->item(0)->getAttribute('href');

    $type = $td2->childNodes->item(0)->textContent;
    $imageURL = $td2->getElementsByTagName('img')->item(0)->getAttribute('src');  

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

Comments

0

I have used following class. http://sourceforge.net/projects/simplehtmldom/

This is very simple and easy to use class.

You can use

$html->find('#RosterReport > tbody', 0);

to find specific table

$html->find('tr')
$html->find('td')

to find table rows or columns

Note $html is variable have full html dom content.

1 Comment

I tried it, but it struggles to load a single row from the table. It couldn't load a single row. This would hang my browser pastebin.com/1XGv4r3h

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.