Exemplo n.º 1
0
    protected void btnGet_Click(object sender, EventArgs e)
    {
        string result = GetPageCode(txtUrl.Text, "gb2312");

        YK.Common.RelaceMarkHelper replace = new YK.Common.RelaceMarkHelper();
        var list = replace.GetMarks("img", result);

        foreach (var str in list)
        {
            ShowInfo.InnerHtml += "<img src=\"" + replace.GetPropertyVal("img", str, "src") + "\"/><br/>";
        }
    }
Exemplo n.º 2
0
    public void GetHtml()
    {
        string    strurl      = txtUrl.Text.ToString(); //欲获取的网页地址 要  http://
        WebClient myWebClient = new WebClient();        //创建WebClient实例myWebClient

        //获取或设置用于对向 Internet 资源的请求进行身份验证的网络凭据。
        myWebClient.Credentials = CredentialCache.DefaultCredentials;

        //从资源下载数据并返回字节数组。(加@是因为网址中间有"/"符号)
        byte[] pagedata = myWebClient.DownloadData(@strurl);
        string result   = Encoding.Default.GetString(pagedata); //如果获取网站页面采用的是GB2312,则使用这句

        //string result = Encoding.UTF8.GetString(pagedata); //如果获取网站页面采用的是UTF-8,则使用这句

        YK.Common.RelaceMarkHelper replace = new YK.Common.RelaceMarkHelper();
        var list = replace.GetMarks("img", result);

        foreach (var str in list)
        {
            ShowInfo.InnerHtml += "<img src=\"" + replace.GetPropertyVal("img", str, "src") + "\"/><br/>";
        }
    }