求助:如何获取网页源代码中元素的值

daisyding1984 2012-11-05 12:37:42
网页源代码:
<a href="http://www.xxx.com/a-1.html">香蕉</a>
<a href="http://www.xxx.com/a-2.html">苹果</a>
<a href="http://www.xxx.com/a-3.html">橘子</a>
<a href="http://www.xxx.com/a-4.html">西瓜</a>

根据橘子获取a标签的href的值:http://www.xxx.com/a-3.html



网页源代码:
<input type="hidden" name="formhash" id="formhash" value="8dd60e99" />
<input type="hidden" name="posttime" id="posttime" value="1352046609" />
<input type="hidden" name="wysiwyg" id="e_mode" value="1" />

获取第二个input的值,即:1352046609



网页源代码:
<input type="hidden" value="2" name="step" />
<input type="hidden" value="" name="pid" />
<input type="hidden" value="new" name="action" />
<input type="hidden" value="149" name="fid" />
<input type="hidden" value="0" name="tid" />
<input type="hidden" value="0" name="article" />
<input type="hidden" value="0" name="special" />
<input type="hidden" value="cn0zz" name="_hexie" />

获取最后一个input的值,即:cn0zz
...全文
342 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
  • 打赏
  • 举报
回复
string v1 = Regex.Match(tempStr,@"(?i)<a[^>]*?href=(['""]?)([^'""]*?)\1[^>]*?>橘子</a>").Groups[2].Value;
                //http://www.xxx.com/a-3.html
                string v2 = Regex.Match(tempStr, @"(?i)<input[^>]*?name=(['""]?)posttime\1[^>]*?value=(['""]?)([^'""]*?)\2[^>]*?>").Groups[3].Value;
                //1352046609
                string v3 = Regex.Match(tempStr, @"(?i)<input[^>]*?value=(['""]?)([^'""]*?)\1[^>]*?name=(['""]?)_hexie\3[^>]*?>").Groups[2].Value;
                //cn0zz
daisyding1984 2012-11-05
  • 打赏
  • 举报
回复
自己顶。。。。。。。。
daisyding1984 2012-11-05
  • 打赏
  • 举报
回复
引用 1 楼 hc1104 的回复:
截取其中的字段就可以了
是人都知道。。。
止境 2012-11-05
  • 打赏
  • 举报
回复
截取其中的字段就可以了

110,499

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧