This question already has an answer here:
- XPath query with PHP 3 answers
If I have the following X(HTML) structure, how do you go about capturing that imgur link deep within the div tree?
I tried several different methods. What I really want is to make a node tree for the div containing "siteTable" because there are many div's within that div that contain more imgur links. If you haven't noticed, this is the html for reddit.
Thanks!
<html lang="en" xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<body class="listing-page hot-page">
<div id="header" role="banner">
<div class="side">
<a name="content"></a>
<div class="content" role="main">
<div class="infobar welcome">
<div id="siteTable" class="sitetable linklisting">
<div class=" thing id-t3_1gh823 over18 odd link " data-downs="5" data-ups="90" data-fullname="t3_1gh823" onclick="click_thing(this)">
<p class="parent"></p>
<span class="rank" style="width:2.20ex;">1</span>
<div class="midcol unvoted" style="width:5ex;">
<a class="thumbnail " href="http://i.imgur.com/FZ1I9wi.jpg">
This is what I know needs to be done:
$dom = new domDocument;
@$dom->loadHTML(file_get_contents($link));
$dom->preserveWhiteSpace = false;
$xpath = new DOMXPath($dom);
$href = $xpath->query('?????');
print_r($tags);
</div>