zoukankan      html  css  js  c++  java
  • 网页抓取的一个小例子

    protected void GetHtml() {
            string url = "http://www.baidu.com/";
           HttpWebRequest wRequest = (HttpWebRequest)WebRequest.Create(url); //设置请求的url
           wRequest.Method = "Post";
           wRequest.ContentType = "application/x-www-form-urlencoded";
           wRequest.Timeout = 1000*60;
           byte[] charbyte = System.Text.Encoding.Default.GetBytes(url);  //格式化参数
           wRequest.ContentLength = charbyte.Length;
           StreamWriter sw = new StreamWriter(wRequest.GetRequestStream()); //字节流
           try { 
               sw.Write(url);
           }catch(Exception ex ){
               
           }finally {
               sw.Close();
           }
    
           StreamReader sr = new StreamReader(wRequest.GetResponse().GetResponseStream()); //开始接受服务器回传
           string responseData = sr.ReadToEnd();
           backResponse.InnerText = responseData;   //得到结果
        }



    来给结果上个图,有图有真相:
           
       也许你说,这么一大堆乱码,看着就头疼,怎么处理呢?下篇我们讲学习正则表达式,谢谢!

      

  • 相关阅读:
    运算符
    数据运算
    login_code
    headless&unittest
    dict-test
    list_test
    string_test
    python1113
    堆排序
    java线程同步问题
  • 原文地址:https://www.cnblogs.com/ypyhy/p/4240861.html
Copyright © 2011-2022 走看看