XPath解析“SRC”来自IMG标签? [英] XPath to Parse "SRC" from IMG tag?
本文介绍了XPath解析“SRC”来自IMG标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
// img [@ class ='照片大']
例如它会返回这个:
< img src =http://example.com/img.jpgclass ='photo-large'/>
但我只需要SRC网址( http://example.com/img.jpg )。任何帮助?
解决方案
你很亲近回答这个问题,我有点不愿意为你回答。然而,下面的XPath应该提供你想要的(当然,源代码是XHTML)。
// img [@ class ='photo-large'] / @ src
有关更多提示,请查看 W3学校。他们有很好的教程,也很好的参考。
Right now I successfully grabbed the full element from an HTML page with this:
//img[@class='photo-large']
for example it would return this:
<img src="http://example.com/img.jpg" class='photo-large' />
But I only need the SRC url (http://example.com/img.jpg). Any help?
解决方案
You are so close to answering this yourself that I am somewhat reluctant to answer it for you. However, the following XPath should provide what you want (provided the source is XHTML, of course).
//img[@class='photo-large']/@src
For further tips, check out W3 Schools. They have excellent tutorials on such things and a great reference too.
这篇关于XPath解析“SRC”来自IMG标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文