繁体   English   中英

使用PHP DOM解析器从Javascript代码获取数据

[英]Using PHP DOM parser to get data from Javascript code

我正在学习解析器,并在研究了Java解析器JSoup之后,尝试使用PHP进行相同的操作。 我正在使用PHP Simple HTML DOM(如果这是最好的解决方案,请不要使用)从URL获取一些数据,但是没有成功。 我如何使用PHP解析器从外部网络的下一个代码中获取8个数字(在bar1附近)和18个数字(在bar0附近)?

 <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>

这是我尝试过的方法,但是它只显示整行,而不仅显示数字:

<?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];


}




?>

使用JSoup的诀窍是:String onMouseOver = doc.select(“ a”)。attr(“ onMouseOver”);

预先感谢您的时间和奉献。

最后,我自己找到了解决方案!!

<?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]." ";



}




?>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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