我正在尝试使用 php dom 和 xpath 获取图像,但该图像没有我可以用来获取它的唯一标识符。我只需要这 1 张图片。
标记如下:
<img alt="Photo of Starbucks Raffles City" style="position: relative; left: 0px; top: -11px;" id="HERO_PHOTO" class="flexibleImage" src="http://media-cdn.tripadvisor.com/media/photo-s/02/39/57/0d/front-of-starbucks.jpg" width="256" height="171">
如果我获取类或 id 并没有多大帮助,因为更多图像具有这些类,是否有办法同时获取 3 个属性?例如,我想找到//img,其中 id 为 A,类为 B,宽度为 C。 类似的东西?
最佳答案
"For example i want to find the //img where the id is A, the class is B and the width is C"
您可以使用 and
运算符简单地组合多个条件。例如,上述语句的 XPath 为:
//img[@id='A' and @class='B' and @width='C']
关于PHP DOM Xpath 获取图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31282843/