1

I am struck in a problem, i want a small amount of data from a site, but this data is present in different pages.

Hence i used curl request to call this pages

Problem:

curl request gives my a html page, and finding that small amount of content is difficult with php as, It is very simple to move through the HTML Dom with JavaScript(jquery). Can i move with same ease with php in HTML Dom

any help would be appreciated , please provide me link of such site also

I am not asking for all the coding , but just a library or link will do

if there is any trick it will also do , a small example like fetching element with ID would be of great help

Thanks

2

1 Answer 1

4

Yes you can. You can use DomDocument and DomXPath to navigate your HTML tree and search it.

$doc = new DOMDocument();
$doc->loadHTML($yourHtml); // HTML as string, use loadHTMLFile() to load a file.
$xpath = new DOMXpath($doc);
$elements = $xpath->query("*/div[@id='yourTagIdHere']");
if (empty($elements) || $elements->length == 0)
    echo "Not found";
else
{
    // $elements now contains a DOMNodeList of matching elements
    // which you can foreach() through.
}
Sign up to request clarification or add additional context in comments.

Comments

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.