简体   繁体   中英

Using PHP DOM parser to get data from Javascript code

I'm learning about parsers and after taking a look at Java parser JSoup I'm trying to do the same with PHP. I'm using PHP Simple HTML DOM (don't now if it's the best solution) to get some data from an url, but without success. How can I take the 8 (near bar1) and 18 (near bar0) numbers from the next code from external web using a PHP parser?

 <table>

 <tr><td><div name='divns6' id='divns6' style='position:relative;visibility:hidden;'       
    width='400' height='160'><table valign=botton cellpadding='0' cellspacing='0' 
    border='0'><tr     valign='bottom'>
  <td width=15 valign="bottom" height=150><a href="javascript:void(null)" 
         onMouseOver="changeImage('bar1','','47',2);activadiv('bar0','18');" 
         onMouseOut="changeImage('bar1','','47',0);desactivadiv('bar1');"><img 
         NAME="barra1" width="11px" height="47" border="0"></a></td>

  <td width=15 valign="bottom" height=150><a href="javascript:void(null)" 
         onMouseOver="changeImage('bar2','','21',2);activadiv('bar1','8');" 
         onMouseOut="changeImage('bar2','','21',0);desactivadiv('bar2');"><img 
         NAME="barra2" width="11px" height="21" border="0"></a></td>

  </td></tr></table>

Here's what I've tried, but It only shows the entire line, not only the number:

<?php include ("simple_html_dom.php"); 

// Create DOM from URL or file
$html = file_get_html('http://www.myurl.com');


// Find all text blocks 


$ret = $html->find('a[onMouseOver]');



for ($count='0'; $count<count($ret);$count++) {

echo $ret[$count];


}




?>

With JSoup the line who do the trick was: String onMouseOver = doc.select("a").attr("onMouseOver");

Thank you in advance for your time and dedication.

Finally I've found the solution on my own!!

<?php include ("simple_html_dom.php"); 

// Create DOM from URL or file
$html = file_get_html('http://www.myweb.com');


 // Find all text blocks 


 $ret = $html->find('a[onMouseOver]');



 for ($count='0'; $count<count($ret);$count++) {

       echo split("'", $ret[$count])[9]." ";



}




?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM