找传奇、传世资源到传世资源站!

C#打开与获取网页源码

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

C#打开与获取网页源码
from clipboard
using Imitate;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Net;
using System.IO;
using System.IO.Compression;
using System.Text.RegularExpressions;
namespace Imitate
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        private void button1_Click(object sender, EventArgs e)
        {
            webBrowser1.ScriptErrorsSuppressed = true; //屏蔽错误信息 C# 系统组件
            webBrowser1.Navigate("https://wxtz.rsmkcq.com/?jump=aHR0cHM6Ly84ODMyMnguY29tP3JpZD05OTQ0NjMmdHlwZTE9Mg%3D%3D");//稳定网址
            //webBrowser1.Navigate("https://215554.com/home");
        }
        ///<h3>请单击“提交”,测试提交按钮的单击事件也被触发了。</h3> 
        ///<button id="btn">提交</button> 
        ///<form action="#" method="get" id="form"> 
        ///<input type="text" name="site" value="www.woiweb.net" readonly/> 
        ///<input id="subbtn" type="submit" value="先别点击此按钮提交" onclick="alert('我已经提交了');"/> 
        ///</form> 
        ///html代码:<h3>请单击“提交”,测试提交按钮的单击事件也被触发了。</h3> 
        ///<button id="btn">提交</button> 
        ///<form action="#" method="get" id="form"> 
        ///<input type="text" name="site" value="www.woiweb.net" readonly/> 
        ///<!--<input id="subbtn" type="submit" value="先别点击此按钮提交" onclick="alert('我已经提交了');"/> --> 
        ///<a id="subbtn" href="javascript:;" onclick="alert('在此调用提交表单的方法')">模拟提交按钮</a> 
        ///</form> 
        ///
        string bak = "<script type=" '"' "text/javascript" '"' ">"
        //string bak = "<script class=" '"' "submit-btn/javascript" '"' ">"
    " var sub = document.getElementById(" '"' "subbtn" '"' ");"
    " var btn = document.getElementById(" '"' "btn" '"' "); "
            //通用方法 
    "   btn.onclick = function() { "
         //sub.click(); 
         "if (/msie/i.test(navigator.userAgent)) " //IE 
             "{ sub.fireEvent(" '"' "onclick" '"' "); } else { "
                 "var e = document.createEvent('MouseEvent'); "
                " e.initEvent('click', false, false); "
             "sub.dispatchEvent(e); } } "
     "</script> ";
        private void button2_Click(object sender, EventArgs e)
        {
            try
            {
                string strBuff = "";
                int byteRead = 0;
                char[] cbuffer = new char[256];
                HttpWebRequest httpReq = (HttpWebRequest)WebRequest.Create(new Uri("https://wxtz.nkrslyev.cn/p4aHJ"));
                HttpWebResponse httpResp = (HttpWebResponse)httpReq.GetResponse();
                Stream respStream = httpResp.GetResponseStream();
                StreamReader respStreamReader = new StreamReader(respStream, System.Text.Encoding.UTF8);
                byteRead = respStreamReader.Read(cbuffer, 0, 256);
                while (byteRead != 0)
                {
                    string strResp = new string(cbuffer, 0, byteRead);
                    strBuff = strBuff strResp;
                    byteRead = respStreamReader.Read(cbuffer, 0, 256);
                }
                respStream.Close();
                //strBuff = strBuff.Replace("</html>", bak " </html>");
                //string html = strBuff;
                MessageBox.Show(strBuff);
               // Regex reg_charset = new Regex(@"(?is)<img[^>]*?scr=(['""\s]?)([^'""\s] )\1[^>]*?>");
                //Regex reg_charset = new Regex("<a.*?type=\"(?<script>.*?)\".*?type=\"(?<script>.*?)\".*?>", RegexOptions.Compiled);
                //if (reg_charset.IsMatch(html))
                //{
                    //MessageBox.Show(reg_charset.Match(html).Groups["type"].Value);
                    //MessageBox.Show(reg_charset.Match(html).Groups["scr"].Value);
                //}
                //webBrowser1.Navigate(strBuff);
                //return strBuff;
            }
            catch (Exception ex)
            {
                //return ex.Message;
            }
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            toolStripProgressBar1.Maximum = 1000;
            webBrowser1.StatusTextChanged = (s, arg) => { toolStripStatusLabel1.Text = webBrowser1.StatusText; };
            webBrowser1.ProgressChanged = (s, arg) =>
            {
                var c = 1.0 * arg.CurrentProgress / arg.MaximumProgress;
                if (c < 0) c = 0;
                if (c > 1) c = 1;
                if (arg.MaximumProgress == 0) c = 0;
                toolStripProgressBar1.Value = (int)(c * 1000);
            };

            System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
            timer.Interval = 20;
            timer.Tick = (s, args) =>
            {
                var l = webBrowser1.Location;
                var p = PointToClient(MousePosition);
                toolStripStatusLabel2.Text = (p.X - l.X) " , " (p.Y - l.Y);
            };
            timer.Start();
        }

        private void button1_Click_1(object sender, EventArgs e)
        {
            webBrowser1.Navigate(textBox1.Text.Trim());
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {

        }

        private void fillToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

        private void navigateToolStripMenuItem_Click(object sender, EventArgs e)
        {

        }

    }
}

评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复