正则表达式识别js跳转的链接
2017-11-20 15:01
351 查看
用Webclient访问链接后返回了跳转页面,页面代码如下,需要把
//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;
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;
相关文章推荐
- Java 使用正则表达式取出图片地址以及跳转的链接地址,来判断死链(一)
- js识别半角字符的正则表达式
- 使用 js+正则表达式为关键词添加链接
- js识别半角字符的正则表达式
- 使用 js+正则表达式为关键词添加链接
- js如何识别中文字符-charCodeAt()、正则表达式
- node.js正则表达式获取网页中所有链接的代码实例
- 转: js 识别中文的正则表达式
- node.js正则表达式获取网页中所有链接的代码实例
- js利用正则表达式筛选并获取字符串中的URL链接(只是筛选完整URL,单独域名不筛选)
- js验证数字正则表达式
- <转>JS总结1--(CSS书写规范和正则表达式)
- JS的正则表达式
- JS正则表达式验证数字非常全
- js的正则表达式学习笔记
- js利用正则表达式检验输入内容是否为网址
- js正则表达式使用
- js验证金额是否符合要求的正则表达式
- js中的正则表达式(二)
- js正则表达式去空格