HTML DOM 解析器无法获取 JavaScript 倒计时
我正在使用 http://simplehtmldom.sourceforge.net/ 中的 HTML DOM 解析器
,然后我遇到了可以无法从源链接中的倒计时 JavaScript 获取文本。
源代码:(这是 Countdown JavaScript)
<div class="timeSection" align="right" style="width:285px;margin:132px 0 0 -50px;position:absolute;">
<div style="width:285px; height:58px;"></div>
<div id="countdown_575" style="padding-left:50px;" class="hasCountdown"><table cellspacing="5" cellpadding="0" width="230" style="" border="0"><tbody><tr><td width="75" align="center">111</td><td width="40" align="center">50</td><td width="70" align="center">49</td></tr></tbody></table></div>
<script type="text/javascript">
jQuery('#countdown_575').countdown({until: +402717 , compact: true,timeSeparator: '',expiryText:'Expired',format:'HMS',expiryUrl:'http://www.ensogo.com.ph/manila/',layout:'<table cellspacing="5" cellpadding="0" width="230" style="" border = "0">' +
'<tr><td width="75" align="center">{hnn}</td><td width="40" align="center">{mnn}</td><td width="70" align="center">{snn}</td></tr></table>'});
</script>
</div>
我的代码:
foreach($ColumnHTML->find('.timeSection') as $getTime)
{
$Temp_Time = $getTime->innertext;
$TimeCode = str_get_html($Temp_Time);
foreach($TimeCode->find('td[width=75]') as $getHour)
{
$Hour = $getHour->plaintext;
}
foreach($TimeCode->find('td[width=40]') as $getMinute)
{
$Minute = $getMinute->plaintext;
}
foreach($TimeCode->find('td[width=70]') as $getSecond)
{
$Second = $getSecond->plaintext;
}
echo $Hour.":".$Minute.":".$Second . "<br/>";
}
然后输出:(带冒号的空白)
::
I'm using HTML DOM Parser from http://simplehtmldom.sourceforge.net/
then I have problem that can't get text from countdown JavaScript in source link.
code from source: (this is Countdown JavaScript)
<div class="timeSection" align="right" style="width:285px;margin:132px 0 0 -50px;position:absolute;">
<div style="width:285px; height:58px;"></div>
<div id="countdown_575" style="padding-left:50px;" class="hasCountdown"><table cellspacing="5" cellpadding="0" width="230" style="" border="0"><tbody><tr><td width="75" align="center">111</td><td width="40" align="center">50</td><td width="70" align="center">49</td></tr></tbody></table></div>
<script type="text/javascript">
jQuery('#countdown_575').countdown({until: +402717 , compact: true,timeSeparator: '',expiryText:'Expired',format:'HMS',expiryUrl:'http://www.ensogo.com.ph/manila/',layout:'<table cellspacing="5" cellpadding="0" width="230" style="" border = "0">' +
'<tr><td width="75" align="center">{hnn}</td><td width="40" align="center">{mnn}</td><td width="70" align="center">{snn}</td></tr></table>'});
</script>
</div>
my code:
foreach($ColumnHTML->find('.timeSection') as $getTime)
{
$Temp_Time = $getTime->innertext;
$TimeCode = str_get_html($Temp_Time);
foreach($TimeCode->find('td[width=75]') as $getHour)
{
$Hour = $getHour->plaintext;
}
foreach($TimeCode->find('td[width=40]') as $getMinute)
{
$Minute = $getMinute->plaintext;
}
foreach($TimeCode->find('td[width=70]') as $getSecond)
{
$Second = $getSecond->plaintext;
}
echo $Hour.":".$Minute.":".$Second . "<br/>";
}
then Output: (blank with colon)
::
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是行不通的,因为这些值是通过 JavaScript 动态插入到客户端的 DOM 中的。如果您想在服务器上捕获这些值,您可以使用表单提交它们。
That will not work, since those values are dynamically inserted into the DOM on the client side via JavaScript. If you want to capture those values on the server, you can submit them using a form.
当您通过 php 解析 html 时,不会执行 javascript,这就是您没有得到结果的原因。你试图做的事情是不可能的。一个简单的方法是在 JavaScript 中使用 ajax 来存储计数器(可能在会话中或数据库表中)。
When you parse html through php the javascript is not executed thats why you dont get a result. That you are trying to do its not possible. A simple way to do it is to use ajax in your javascript to store your counter (maybe in a session or in a database table).