![](/img/trans.png)
[英]PHP Simple HTML DOM Parser for JavaScript Code Within the Page
[英]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.