title: How to get tag's attribute using PHP simple HTML DOM parser
body: <p>I am using the <a href="http://simplehtmldom.sourceforge.net/" rel="nofollow noreferrer">PHP Simple HTML DOM parser</a> 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.</p>
  
  <pre><code>&lt;div id="section1"&gt;
     &lt;h1&gt;Some content&lt;/h1&gt;
     &lt;p&gt;Some content&lt;/p&gt;
     ............
      &lt;&lt;Not fixed number of element&gt;&gt;
     ............
     &lt;script&gt; &lt;&lt;Some script&gt;&gt;&lt;/script&gt;
     &lt;video&gt;
       &lt;source src="www.exmple.com/34/exmple.mp4"&gt;
     &lt;/video&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>I tried with JavaScript and i could do the same like this</p>
  
  <pre><code>document.getElementById("section1").getElementsByTagName("source")[0].getAttribute("src");
  </code></pre>
  
  <p>But when i tried with PHP Dom parser i m not getting any data.
  Here is how my code looks likes</p>
  
  <pre><code>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-&gt;getElementById('section1')-&gt;find('source',0)-&gt;getAttribute('src');
  var_dump($linkURL); 
  </code></pre>
  
  <p>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 <code>var dump $obj_content</code> i get lot of dom element</p>
  
  <p>I tried to follow these posts from stackoverflow which are similar to mine , but these did not help me.</p>
  
  <ol>
  <li><a href="https://stackoverflow.com/questions/819182/how-do-i-get-the-html-code-of-a-web-page-in-php">How do I get the HTML code of a web page in PHP?</a></li>
  <li><a href="https://stackoverflow.com/questions/20200304/php-simple-html-dom">PHP Simple HTML DOM</a></li>
  <li><a href="https://stackoverflow.com/questions/16147044/php-simple-html-dom-parser-call-to-a-member-function-children-on-a-non-object">PHP Simple HTML DOM Parser Call to a member function children() on a non-object</a></li>
  <li>And their manual <a href="http://simplehtmldom.sourceforge.net/manual.htm" rel="nofollow noreferrer">http://simplehtmldom.sourceforge.net/manual.htm</a> </li>
  </ol>
  
  <p>Can anyone please help me</p>
  
  <p>Thank you</p>