如何获得标题和完整的课程价值? [英] How do I get the title and complete class value?

查看:65
本文介绍了如何获得标题和完整的课程价值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个查询

1)< div class = ab title =我的标题>
如何获得标题和完整的班级价值? ( a始终是固定类,而不是 b。第二类可以是任何东西,也可以具有两个以上的类。)

1) <div class="a b" title="my title"> How do I get the title and complete class value ? ('a' always be a fixed class but not 'b'. Second class can be anything and also possiblity to have more than two classes.)

2)< h1><一个link = dynamic_link class = fix-class>我的内容< / a>< / h1>
获取 a href标签的所有属性(链接,类..),它们仅属于 h1标签

2) <h1><a link="dynamic_link" class="fix-class">my content< /a>< /h1> Get all attributes(link,class..) of 'a href' tag which belongs to only 'h1' tag

请帮帮我,因为我从过去两天开始一直坚持这一观点,无法从Google获得任何解决方案。这是我对stackoverflow的第一个问题。希望我能得到很多帮助。

Please help me out because I stuck on this point from last two days and not able to get any solution from google. This is my first quetion on stackoverflow. I hope I get many hands for help. Thanks in advance.

推荐答案

您应该使用XPath查询HTML或XML 。要使用XPath,您必须将HTML加载到DOMDocument对象中

You should use XPath to query HTML or XML. To use XPath you have to load you HTML into a DOMDocument object.

/* $doc is an instance of DOMDocument */

$xpath = new DOMXPath( $doc );

$myElemnts = $xpath->query( '//li[contains(concat(" ", normalize-space(@class), " "), " classA ")]' );

XPath类匹配示例来自 http://www.cowburn.info/2009/06/15/xpath-css-class/

The XPath class matching example is from http://www.cowburn.info/2009/06/15/xpath-css-class/

请参考网络上许多XPath手册之一,以了解如何获取以XPath编写的查询。

Please refer to one of the many XPath manuals on the web, to find out how to get you queries written in XPath.

这篇关于如何获得标题和完整的课程价值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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