HTML Agility Pack查找以。开头的ID

时间:2011-08-30 12:29:29

标签: c# .net xml xpath html-agility-pack

我是XPath的完全noob,我正在申请从网站获取数据,我需要找到两件事:

1-所有以ctl00_Main_GridView_lieutenants

开头的span标记

2- span-.....r的父标签的href ..我将尝试解释:

<a href="something.html"><span id="ctl00_Main_GridView_lieutenants_ctl03_lbl_nick">Text</span></a>

我需要文字和链接;)

1 个答案:

答案 0 :(得分:11)

//span[starts-with(@id, 'ctl00_Main_GridView_lieutenants')]

选择@idctl00_Main_GridView_lieutenants

开头的所有范围
//a[span[starts-with(@id, 'ctl00_Main_GridView_lieutenants')]]/@href

选择所有@href aspan@id ctl00_Main_GridView_lieutenants以{{1}}

开头的小孩{{1}}