加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则表达式 取出img标签 保存于指定路径

发布时间:2020-12-14 01:11:55 所属栏目:百科 来源:网络整理
导读:using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Net; using System.IO; using System.Text; using System.Text.RegularExpressions; namespac

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Net;
using System.IO;
using System.Text;
using System.Text.RegularExpressions;

namespace DloadPic
{
public partial class WebForm1 : System.Web.UI.Page
{
protected void Page_Load(object sender,EventArgs e)
{
string allstr = "<p dir="ltr"><b>首先小编提醒广大车友们,以下应急方法都是有前提的:</b></p> <p dir="ltr">  <b>1、你没有影响他人通过,没横在人行道上,没挡住了其他车辆。</b></p> <p dir="ltr"><b>  2、你没有逆向停车。</b></p> <p dir="ltr">";
allstr += "<img src="
http://mmbiz.qpic.cn/mmbiz/1AduwlOjUXlYnmR39eBSwp50G5SKib3hPAjbkWnMibSyg3tu5e54TRF1hVyzwWr0BdEgQh9WwpwhkVQ5apeibMV1Q/640?wx_fmt=jpeg&wxfrom=5&tp=webp"><br></p> <p dir="ltr">  排除上面这两条后,如果交警正准备对你的停车行为进行";
allstr += "取证,<b>你只需要迅速拉开车门,回到驾驶位置,正常驶离就可以了。</b>因为证据照片中,驾驶位置上有驾驶员的,是不能作为“机动车违反规定停放且驾驶人不在现场或在现场拒绝立即驶离,妨碍其他车辆、行人通行的”行为进行处罚的。<br></p> <p dir="ltr">";
allstr += "<img src="
http://mmbiz.qpic.cn/mmbiz/1AduwlOjUXlYnmR39eBSwp50G5SKib3hPf1k0Vrx12u3EQqmQEA0icCWV10HzicL2ZkHLaF46D2HbRZryZK39XiaTA/640?wx_fmt=jpeg&wxfrom=5&tp=webp"><br></p> <p dir="ltr">  <b>如果交警正准备给你的车贴条,你可以边打开手";
allstr += "机的录像功能(最好设置有快捷方式)边告诉交警你临时停了一下现在马上离开。</b>如果交警仍然执意贴条,那么这段录像就可以作为申诉和复议证据。因为如果驾驶人在场,交警应该是指出违法行为,予以口头警告,令驾驶人立即驶离,驾驶人只要快速驶离即可。";
allstr += "</p> <p dir="ltr">  <img src="
http://mmbiz.qpic.cn/mmbiz/1AduwlOjUXlYnmR39eBSwp50G5SKib3hPtD8FYz6gsOAK3GxHtN6hU9A2ibuHeFJYgXlm6Z1PkbgANiap04BNnueg/640?wx_fmt=jpeg&wxfrom=5&tp=webp"><br></p> <p dir="ltr">  微群里一小伙伴在医院临时等人";
allstr += ",我把车停在路边,降下玻璃等待,后视镜里可以看到一位交警由远及近的一辆一辆的贴条,贴到我的车时候发现驾驶位置有人,人家扭头就走了。一说明,这位交警很清楚驾驶员在现场不能处罚;二说明,口头警告对他来说没有任何意义,不如节约时间到路对面继续";
allstr += "贴条,更具有现实价值。</p> <p dir="ltr">  <img src="
http://mmbiz.qpic.cn/mmbiz/1AduwlOjUXlYnmR39eBSwp50G5SKib3hPUh33wnDpYG4hhW1Gr9eCqvu9vc0IWluZaBnYTpTicjKvxctARiaRnliag/640?wx_fmt=jpeg&wxfrom=5&tp=webp"><br></p> <p dir="ltr">  朋友";
allstr += "们,仔细阅读交通法,学习交通法,遵守交通法是保证安全,避免处罚的最有效方法。争辩、吵架、送烟、生气、发泄都很OUT!效果不好,还解决不了问题。</p> <p dir="ltr">  <img ";
allstr += "src="http://mmbiz.qpic.cn/mmbiz/1AduwlOjUXlYnmR39eBSwp50G5SKib3hPgTUyALQPkTsIIF55ZumuuTcYbGL43lttgBDTFVlrficnbeMwK3O42nQ/640?wx_fmt=jpeg&wxfrom=5&tp=webp"></p> <p dir="ltr"><img ";
allstr += "src="http://mmbiz.qpic.cn/mmbiz/DaFXKpOGEkylF3es0sMdI99dbBO3ia0c6olvkGrSoBiaDCiaPlI1kUgdvNrnchmdbg1hmIkvuVwa8OuXgnuLbXevQ/640?wxfrom=5&wx_fmt=jpeg&tp=webp"><b><b></b></b></p>";
Regex reg = new Regex("<imgs+src="(.*?)"");
// MatchCollection matches = reg.Matches(allstr);
allstr = reg.Replace(allstr,new MatchEvaluator(matchreplace));
string str = allstr;

}

public string matchreplace(Match m_match)
{
string m_return = m_match.Groups[0].Value;
string m_picurl = m_match.Groups[1].Value;
string temppartsrc = m_picurl.Substring(0,m_picurl.IndexOf('?'));
string temp = m_picurl.Substring(m_picurl.IndexOf("wx_fmt=") + 7);
string pictype = temp.Substring(0,temp.IndexOf("&"));
string src = temppartsrc + "." + pictype;
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(src);
request.AllowAutoRedirect = true;

WebProxy proxy = new WebProxy();
proxy.BypassProxyOnLocal = true;
proxy.UseDefaultCredentials = true;
request.Proxy = proxy;
WebResponse response = request.GetResponse();
string virthpath = "";
using (Stream stream = response.GetResponseStream())
{
using (MemoryStream ms = new MemoryStream())
{
Byte[] buffer = new Byte[1024];
int current = 0;
while ((current = stream.Read(buffer,buffer.Length)) != 0)
{
ms.Write(buffer,current);
}
byte[] arry = ms.ToArray();
virthpath = "./image/" + DateTime.Now.ToString("yyyyMMddhhmmss") + "." + pictype;
string path = Server.MapPath(virthpath);
File.WriteAllBytes(path,arry);
}
}
m_return = m_return.Replace(m_picurl,virthpath);
return m_return;
}

} }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读