c# 写个简单的爬虫。注:就一个方法,没有注释,自己猜~哈哈
Posted wzl521224
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了c# 写个简单的爬虫。注:就一个方法,没有注释,自己猜~哈哈相关的知识,希望对你有一定的参考价值。
和我,在成都的街头走一走,哦~喔~哦~
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# 写个简单的爬虫。注:就一个方法,没有注释,自己猜~哈哈的主要内容,如果未能解决你的问题,请参考以下文章
半小时就能学会的简单爬虫项目:爬取豆瓣电影数据(包含注释,源码)