码迷,mamicode.com
首页 > Windows程序 > 详细

c# 写个简单的爬虫。注:就一个方法,没有注释,自己猜~哈哈

时间:2019-05-23 09:36:04      阅读:184      评论:0      收藏:0      [点我收藏+]

标签:exchange   out   pre   xhtml   copy   amp   copyto   span   json   

和我,在成都的街头走一走,哦~喔~哦~

public JsonResult GetHtml()
        {
            string url = "http://www.xxxxxxxxxxxxxxxxxx.com/index.php?f=order&no=618621";//网站地址
            HttpWebRequest Myrq = (HttpWebRequest)WebRequest.Create(url);
            Myrq.KeepAlive = false;
            Myrq.Timeout = 30*1000;
            Myrq.Method = "GET";
            Myrq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
            Myrq.Host = "www.xxxxxxxxxxxxxx.com";
            Myrq.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36";

            HttpWebResponse myrp = (HttpWebResponse)Myrq.GetResponse();

            if (myrp.StatusCode != HttpStatusCode.OK)
            {
                return ApiSuccessResult("no ok");
            }
            using (StreamReader sr = new StreamReader(myrp.GetResponseStream()))
            {
                return ApiSuccessResult(sr.ReadToEnd()); //返回爬到的网页
            }

        }

 

public JsonResult GetHtml()
        {
            string url = "http://img.xxxxxxxxxxxxxxxxxx.com/7a530ea8ffc84a13efdcfc61c68ad8d5"; //图片地址
            HttpWebRequest Myrq = (HttpWebRequest)WebRequest.Create(url);
            Myrq.KeepAlive = false;
            Myrq.Timeout = 30*1000;
            Myrq.Method = "GET";
            Myrq.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3";
            Myrq.UserAgent = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.169 Safari/537.36";

            HttpWebResponse myrp = (HttpWebResponse)Myrq.GetResponse();

            if (myrp.StatusCode != HttpStatusCode.OK)
            {
                return ApiSuccessResult("no ok");
            }

            using (FileStream fs = new FileStream("1.jpg",FileMode.Create))
            {
                myrp.GetResponseStream().CopyTo(fs);
                return ApiSuccessResult("ok");
            }
        }

技术图片

技术图片

 

c# 写个简单的爬虫。注:就一个方法,没有注释,自己猜~哈哈

标签:exchange   out   pre   xhtml   copy   amp   copyto   span   json   

原文地址:https://www.cnblogs.com/wzl521224/p/10909781.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!