如何过去网页源码某连接?

小A-2013 2012-10-11 09:06:56
请问如何获取某网页源码中的 连接


<span class="skin-blue">
<a class="small-btn" href="http://###.com/trade/logis_type=1&biz_order_id=231417366739868&biz_type=200"
target="_blank"> 标题
</a>

</span>
如何获取这个网址
http://###.com/trade/logis_type=1&biz_order_id=231417366739868&biz_type=200
然后在获取 红色的数
在然后将红色的数和网址赋给 变量

...全文
764 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
小A-2013 2012-10-11
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

那就再增加点条件:
C# code
string s = @"<span class=""skin-blue"">
<a class=""small-btn"" href=""http://###.com/trade/logis_type=1&biz_order_id=231417366739868&biz_type=200""
target=""_bla……
[/Quote]

我说怎么获取不到呢。 原来我这个网页需要登录的
你有什么好的办法能登陆获取源码吗?
我用的webBrowser手工登陆的 可以直接用WebBrowser登陆后在 获取源码吗
dalmeeme 2012-10-11
  • 打赏
  • 举报
回复
那就再增加点条件:
		string s = @"<span class=""skin-blue"">
<a class=""small-btn"" href=""http://###.com/trade/logis_type=1&biz_order_id=231417366739868&biz_type=200""
target=""_blank""> 标题
</a>
</span>";
Match match = Regex.Match(s, @"(?is)<span class=""skin-blue"">\s*<a class=""small-btn"" href=""(?<href>.*?id=(?<id>\d+).*?)"".*?>[^<>]+</a>\s*</span>");
Response.Write(match.Groups["href"].Value + "<br/>");
Response.Write(match.Groups["id"].Value);

就你贴的这段来说应该是可以的。
小A-2013 2012-10-11
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 的回复:]

C# code
string s = @"<span class=""skin-blue"">
<a class=""small-btn"" href=""http://###.com/trade/logis_type=1&biz_order_id=231417366739868&biz_type=200""
target=""_blank""> 标题
……
[/Quote]
能加你QQ帮我弄弄吗? 我QQ:630555865
按你说的没有搞好
dalmeeme 2012-10-11
  • 打赏
  • 举报
回复
		string s = @"<span class=""skin-blue"">
<a class=""small-btn"" href=""http://###.com/trade/logis_type=1&biz_order_id=231417366739868&biz_type=200""
target=""_blank""> 标题
</a>
</span>";
Match match = Regex.Match(s, @"(?is)<a class=""small-btn"" href=""(?<href>.*?id=(?<id>\d+).*?)"".*?>[^<>]+</a>");
Console.WriteLine(match.Groups["href"].Value);
Console.Write(match.Groups["id"].Value);

输出:
http://###.com/trade/logis_type=1&biz_order_id=231417366739868&biz_type=200
231417366739868
threenewbee 2012-10-11
  • 打赏
  • 举报
回复
string s = System.Text.RegularExpression.Regex.Match(html, @"biz_order_id=(\d+)&").Groups[1].Value;

109,897

社区成员

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

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

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