用Webclient访问链接后返回了跳转页面,页面代码如下,需要把
http://kd.szty56.com:8086/xms/client/order_online!print.action?userToken=6f6980b4633c4f03b2eb294054e11f01&trackingNo=LS185519295CN&pageSizeCode=6
这个链接解析出来
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>打印</title>
</head>
<body>
<script type="text/javascript">
var printUrl = "http://kd.szty56.com:8086/xms/client/order_online!print.action?userToken=6f6980b4633c4f03b2eb294054e11f01&trackingNo=LS185519295CN&pageSizeCode=6";
location.href = printUrl;
</script>
</body>
</html>
//1.解析出跳转链接字符串,如printUrl = "http://kd.szty56.com:8086/xms/client/order_online!print.action?userToken=6f6980b4633c4f03b2eb294054e11f01&trackingNo=LS185519295CN&pageSizeCode=6"
string link = "";
MatchCollection matches = Regex.Matches(strHtml, "printUrl\\s*=\\s*\".*?\"", RegexOptions.IgnoreCase);
link =matches[0].Groups[0].Value;
//2.从上面字符串中解析出链接,解析出双引号包围的内容
string pattern = "(?<=\").*?(?=\")";
string realLink = Regex.Match(link, pattern).Value;