【发布时间】:2014-08-14 20:10:58
【问题描述】:
我正在使用 php 和简单的 html dom
http://simplehtmldom.sourceforge.net/manual.htm
我正在尝试从下面的 addthis 代码中提取 facebook、twitter、google、youtube 和 pinterest 用户名..
<!-- AddThis Follow BEGIN -->
<div class="addthis_toolbox addthis_default_style" style="margin-top:-3px;">
<a tabindex="2" class="addthis_button_facebook_follow" style="padding:3px 6px;" addthis:userid="namehere"></a>
<a tabindex="3" class="addthis_button_twitter_follow" style="padding:3px 6px;" addthis:userid="namehere"></a>
<a tabindex="4" class="addthis_button_google_follow" style="padding:3px 6px;" addthis:userid="namehere"></a>
<a tabindex="5" class="addthis_button_youtube_follow" style="padding:3px 6px;" addthis:userid="namehere"></a>
<a tabindex="6" class="addthis_button_pinterest_follow" style="padding:3px 6px;" addthis:userid="namehere"></a>
</div>
<script type="text/javascript" src="//s7.addthis.com/js/300/addthis_widget.js#pubid=ra-51e6691575bd9b10"></script>
<!-- AddThis Follow END -->
如何使用简单的 html dom 获取用户名?
我试过运行这个...
$html = file_get_html('http://www.domain.com/');
foreach($html->find('a[class=addthis_button_facebook_follow]') as $element)
echo $element->class;
输出类名:
addthis_button_facebook_follow
但是如何返回 addthis:userid 值?
addthis:userid
【问题讨论】:
-
试试这个:
$name = 'addthis:userid'; echo $element->$name;
标签: php web-scraping simple-html-dom