我有这样的div:
<div class="widget-archive-monthly widget-archive widget">
<h3 class="widget-header">Monthly <a href="http://myblog.com/blogs/my_name/archives.html">Archives</a></h3>
<div class="widget-content">
<ul>
<li><a href="http://myblog.com/blogs/my_name/2010/10/">October 2010</a></li>
<li><a href="http://myblog.com/blogs/my_name/2010/09/">September 2010</a></li>
<li><a href="http://myblog.com/blogs/my_name/2010/08/">August 2010</a></li>
<li><a href="http://myblog.com/blogs/my_name/2010/07/">July 2010</a></li>
<li><a href="http://myblog.com/blogs/my_name/2010/06/">June 2010</a></li>
<li><a href="http://myblog.com/blogs/my_name/2010/05/">May 2010</a></li>
<li><a href="http://myblog.com/blogs/my_name/2010/04/">April 2010</a></li>
<li><a href="http://myblog.com/blogs/my_name/2010/03/">March 2010</a></li>
<li><a href="http://myblog.com/blogs/my_name/2010/02/">February 2010</a></li>
<li><a href="http://myblog.com/blogs/my_name/2010/01/">January 2010</a></li>
<li><a href="http://myblog.com/blogs/my_name/2009/12/">December 2009</a></li>
<li><a href="http://myblog.com/blogs/my_name/2009/11/">November 2009</a></li>
<li><a href="http://myblog.com/blogs/my_name/2009/10/">October 2009</a></li>
<li><a href="http://myblog.com/blogs/my_name/2009/09/">September 2009</a></li>
<li><a href="http://myblog.com/blogs/my_name/2009/08/">August 2009</a></li>
<li><a href="http://myblog.com/blogs/my_name/2009/07/">July 2009</a></li>
<li><a href="http://myblog.com/blogs/my_name/2009/06/">June 2009</a></li>
<li><a href="http://myblog.com/blogs/my_name/2009/05/">May 2009</a></li>
<li><a href="http://myblog.com/blogs/my_name/2009/04/">April 2009</a></li>
<li><a href="http://myblog.com/blogs/my_name/2009/03/">March 2009</a></li>
<li><a href="http://myblog.com/blogs/my_name/2009/02/">February 2009</a></li>
</ul>
</div>
</div>
我正在尝试在widget-content
div。
如何使用xpath定位这些链接并忽略页面上的任何其他链接,例如“Archives”链接,以便我最终只使用这些值:
http://myblog.com/blogs/my_name/2010/10/
http://myblog.com/blogs/my_name/2010/09/
http://myblog.com/blogs/my_name/2010/08/
http://myblog.com/blogs/my_name/2010/07/
... etc ...
答案 0 :(得分:21)
//div[@class="widget-content"]//a/@href
这应该为您提供仅在widget-content
DIV内的链接的href值。
答案 1 :(得分:0)
相对答案= XPath: find link URL by link text
"//a/@href"