I am using the PHP Simple HTML DOM parser to scrap website data, but unfortunately not able to extract the data i want to. I have also tried to google and look in the documentation but could not solve the issue. The code structure of what i am trying to scrap is something like this.
<div id="section1">
<h1>Some content</h1>
<p>Some content</p>
............
<<Not fixed number of element>>
............
<script> <<Some script>></script>
<video>
<source src="www.exmple.com/34/exmple.mp4">
</video>
</div>
I tried with JavaScript and i could do the same like this
document.getElementById("section1").getElementsByTagName("source")[0].getAttribute("src");
But when i tried with PHP Dom parser i m not getting any data. Here is how my code looks likes
require ''.$_SERVER['DOCUMENT_ROOT'].'/../lib/simplehtmldom/simple_html_dom.php';
$html_content = get($url); //This is cURL function to get website content.
$obj_content = str_get_html($html_content);
$linkURL = $obj_content->getElementById('section1')->find('source',0)->getAttribute('src');
var_dump($linkURL);
This results in an empty string. I also tried changing to code a bit here and there but none of those works every time came blank. But if i var dump $obj_content
i get lot of dom element
I tried to follow these posts from stackoverflow which are similar to mine , but these did not help me.
- How do I get the HTML code of a web page in PHP?
- PHP Simple HTML DOM
- PHP Simple HTML DOM Parser Call to a member function children() on a non-object
- And their manual http://simplehtmldom.sourceforge.net/manual.htm
Can anyone please help me
Thank you