简单DOM和< li> [英] Simple DOM and <li>

查看:227
本文介绍了简单DOM和< li>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经尝试了几种不同的方式,没有任何效果。 (我尝试过如何使用简单HTML模拟子选择器的所有示例DOM?)使用代码,改变我需要的,即class = xxx和url。

I've tried this a few different ways and nothing seems to work. (I tried all examples at How to imitate child selector with Simple HTML DOM?) Used code as is, changing what I needed for my needs, ie class=xxx and the url.

所以我正在尝试从网页中提取一些信息。就DOM而言,没有孩子可以使用,并且使用xpath方法让我没有返回任何东西。我猜我在做错事

So I'm trying pull out some information from a web page. There are no children to work with as far as DOM is concerned and using the xpath method got me nothing returned. I'm guessing I'm doing something wrong.

<div id="wpp-6" class="widget popular-posts">
    <div class="widget_title">POPULAR</div><!-- Wordpress Popular Posts Plugin v2.3.2         [Widget] [daily] [regular] -->
    <ul>
        <li>
            <a href="http://link.html" title="Title of post" class="wpp-post-title">THE DATA I    WANT</a> <span class="post-stats"></span>
        </li>
        <!-- More lists -->
    </ul>
</div>

之后还有大约9个列表语句。
任何建议?

There are about 9 more list statements after that. Any suggestions?

推荐答案

使用 PHP简单的HTML DOM解析器,您可以轻松地执行,只需下载 simple_html_dom.php 文件从这里,并使用如下。

Useing PHP Simple HTML DOM Parser you can do it easily, Just download the simple_html_dom.php file from here and use it as follows.

include('simple_html_dom.php');
$html=file_get_html('http://psfk.com');
foreach($html->find('div#wpp-6 ul li a') as $a){
    echo $a->innertext.'<br />';
}



输出将(2013年1月14日星期一测试)



Output will be (Tested on Monday January 14, 2013)


Google流感地图描绘了美国最严重的疫情

Google Flu Map Depicts Worst Outbreaks In The USA

Scotch-Tape Portraits Contort Human Faces [

Scotch-Tape Portraits Contort Human Faces [Pics]

新设计为奥威尔十九大四大亮点
审查主题

New Design For Orwell’s Nineteen Eighty-Four Highlights Theme Of Censorship

伏特加从过滤白酒模型[视频]

Vodka Made From Filtering The Liquor Over Nude Models [Video]

三星推出灵活的屏幕

麦当劳在澳大利亚的名称

McDonald’s Changes Its Name In Australia

三星的透明屏幕是未来的零售窗口
[CES]

Samsung’s Transparent Screen Is The Retail Window Of The Future [CES]

Dita Von Teese将QR码直接插入她的衣服中

Dita Von Teese Sews QR Codes Directly Into Her Clothing

Abercrombie&惠誉老板让飞行员只穿拳击手
&私人飞机上的凉鞋

Abercrombie & Fitch Boss Makes Flight Attendants Wear Only Boxers & Sandals On Private Jet

镜像应用程序显示女性如果他们继续喝酒,他们将如何年龄

Mirror App Shows Women How They Will Age If They Keep Drinking

如果您要使用链接打印标题,如< a> ...< / a> 然后只需使用 echo $ a

If you want to print the title with link like <a>...</a> then just use echo $a

这篇关于简单DOM和&lt; li&gt;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆