赞
踩
Accept text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8 Accept-Encoding gzip, deflate, br Accept-Language zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2 Connection keep-alive Cookie BAIDUID=9832FF7A5F42D797C0E5BC0E831FDB0D:FG=1; BIDUPSID=7FBB3CAF6CCE501130E43B0144749C48; PSTM=1635568912; BD_UPN=133352; __yjs_duid=1_4c291d5daa44deb2b2ce899e2304c7581635573377095; BDUSS=JBT1pNdW94MGhHZG1sd1lQU3hNWFNNdk0wRjhlU1JqU3pWUGliQ1BKR1NjN0ZoRVFBQUFBJCQAAAAAAAAAAAEAAAAQ9LKwMTU2MTk5Njg1MDd5AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAJLmiWGS5olhYT; H_PS_PSSID=35358_34448_35104_31660_35239_34584_34504_34578_35392_35321_26350_35210_35301; BDORZ=B490B5EBF6F3CD402E515D22BCDA1598; …KKJx2PPWeIJo5t5xhh8bhUJiBbFHBan7VlbIXKohJh7FM4tW3J0ZyxomtfQxtNRJ0DnjtnLhbC_wj5K2D6b0epJf-K6E2I5jBRu8Kb7Vbpbv5fnkbfJBDl5G2f7EJebxBPoxbx5jJCONyT_-KP47yajK2-nlbKuDKxTTtJFWoq7jjDcpQT8r0UDOK5OibCrzWMT1ab3vOPI4XpO1ef0zBN5thURB2DkO-4bCWJ5TMl5jDh3Mb6ksDMDtqtJHKbDf_CDa3e; __sec_t_key=202d5340-4a13-4c34-b5e8-ad386b2e46db; delPer=0; BD_CK_SAM=1; PSINO=6; BA_HECTOR=0l8h0gag8h058ha0k31gqov1j0r; COOKIE_SESSION=2378_6_1_1_10_1_1_0_1_1_0_0_2379_0_2_3_1638693940_1638690929_1638693938%7C9%231337_27_1638690926%7C9; BDSVRTM=0 Host www.baidu.com Sec-Fetch-Dest document Sec-Fetch-Mode navigate Sec-Fetch-Site none Sec-Fetch-User ?1 Upgrade-Insecure-Requests 1 User-Agent Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0
using System.IO; using System.Text; using System.Net; public class Reptile { public string url{get;set;} public string html{get;set;} public Reptile(string _url) { url=_url; } public void DoRequest(){ HttpWebRequest request=(HttpWebRequest)HttpWebRequest.Create(url); //设置请求方法 request.Method="GET"; //设置请求头 request.UserAgent="Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:94.0) Gecko/20100101 Firefox/94.0"; //获取resonse WebResponse response= request.GetResponse(); //获取结果转化为string using(Stream stream=response.GetResponseStream()){ using(StreamReader reader=new StreamReader(stream,Encoding.UTF8)){ this.html=reader.ReadToEnd(); } } System.Console.WriteLine(html); } } ------------------------- static void Main(string[] args) { Reptile robj=new Reptile("https://www.baidu.com/"); robj.DoRequest(); }
如果你看到控制台输出了一堆html js css 那就表示成功了!
下一篇文章我们将说说如何解析这一堆标签 ,如何下载网络图片
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。