• 大小: 118KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-06-06
  • 语言: C#
  • 标签: 控制IE  

资源简介

使用IE API 简单控制IE浏览器,获取html,文本框赋值,点击按钮,控制滚动条位置,模拟浏览等功能。

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace IHtmlDocument
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private int height = 0;
        private mshtml.HTMLDocument doc = null;
        private void button1_Click(object sender EventArgs e)
        {
             System.Diagnostics.Process.Start(@“C:\Program Files\Internet Explorer\IEXPLORE.EXE“ textBox1.Text);
        }

        private void button2_Click(object sender EventArgs e)
        {
            //获取Document对象
            doc = HTMLHelper.GetHTMLDocumentByURL(this.textBox1.Text);
            if (doc != null)
            {
                //获取body对象
                mshtml.IHTMLElement body = doc.body;
                this.textBox2.Text = doc.title; //获取标题
                this.textBox3.Text = body.outerHTML;  //获取body
                this.textBox4.Text = doc.documentElement.outerHTML; //获取html
                this.textBox5.Text = body.offsetHeight.ToString(); //网页内容高度
                height = body.offsetHeight;
            }
            else
            {
                MessageBox.Show(“未找到对象。“);
            }
        }

        private void button3_Click(object sender EventArgs e)
        {
            if (doc != null)
            {
                doc.parentWindow.scrollTo(0 0);
            }
            else
            {
                MessageBox.Show(“未找到对象,先获取。“);
            }
        }

        private void button4_Click(object sender EventArgs e)
        {
            if (doc != null)
            {
                doc.parentWindow.scrollTo(0 height / 2);
            }
            else
            {
                MessageBox.Show(“未找到对象,先获取。“);
            }
        }

        private void button5_Click(object sender EventArgs e)
        {
            if (doc != null)
            {
                doc.parentWindow.scrollTo(0 height);
            }
            else
            {
                MessageBox.Show(“未找到对象,先获取。“);
            }
        }

        private void button6_Click(object sender EventArgs e)
        {
            if (doc != null)
            {
                mshtml.IHTMLElementCollection inputs = doc.getElementsByTagName(“input“);
                foreach (mshtml.IHTMLElement b in inputs)
                {
                    if (b.className == this.textBox7.Text) //class=“search-value“
                    {
                        b.innerText = this.textBox6.Text;  //文本框赋值
                    }
                }
            }
            else
            {
                MessageBox.Show(“未找到对象,先获取。“);
            }
        }

        private void button7_Click(object sender EventArgs e)
 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        187  2015-01-22 23:45  IHtmlDocument\IHtmlDocument\App.config

     文件      21504  2015-01-23 20:25  IHtmlDocument\IHtmlDocument\bin\Debug\IHtmlDocument.exe

     文件        187  2015-01-22 23:45  IHtmlDocument\IHtmlDocument\bin\Debug\IHtmlDocument.exe.config

     文件      36352  2015-01-23 20:25  IHtmlDocument\IHtmlDocument\bin\Debug\IHtmlDocument.pdb

     文件      22984  2015-01-23 20:25  IHtmlDocument\IHtmlDocument\bin\Debug\IHtmlDocument.vshost.exe

     文件        187  2015-01-22 23:45  IHtmlDocument\IHtmlDocument\bin\Debug\IHtmlDocument.vshost.exe.config

     文件      15360  2015-01-23 02:42  IHtmlDocument\IHtmlDocument\bin\Debug\IHtmlDocument2.exe

     文件        187  2015-01-22 23:45  IHtmlDocument\IHtmlDocument\bin\Debug\IHtmlDocument2.exe.config

     文件      28160  2015-01-23 02:42  IHtmlDocument\IHtmlDocument\bin\Debug\IHtmlDocument2.pdb

     文件        187  2015-01-22 23:45  IHtmlDocument\IHtmlDocument\bin\Debug\IHtmlDocument2.vshost.exe.config

     文件        490  2012-06-06 02:06  IHtmlDocument\IHtmlDocument\bin\Debug\IHtmlDocument2.vshost.exe.manifest

     文件       6137  2015-01-23 20:25  IHtmlDocument\IHtmlDocument\Form1.cs

     文件      14742  2015-01-23 20:25  IHtmlDocument\IHtmlDocument\Form1.Designer.cs

     文件       5817  2015-01-23 20:25  IHtmlDocument\IHtmlDocument\Form1.resx

     文件       3176  2015-01-23 20:24  IHtmlDocument\IHtmlDocument\HTMLHelper.cs

     文件       4228  2015-01-23 17:12  IHtmlDocument\IHtmlDocument\IHtmlDocument.csproj

     文件     120832  2013-08-10 15:29  IHtmlDocument\IHtmlDocument\Interop.SHDocVw.dll

     文件       1428  2015-01-23 05:29  IHtmlDocument\IHtmlDocument\obj\Debug\DesignTimeResolveAssemblyReferences.cache

     文件       7193  2015-01-23 17:04  IHtmlDocument\IHtmlDocument\obj\Debug\DesignTimeResolveAssemblyReferencesInput.cache

     文件       2380  2015-01-23 20:25  IHtmlDocument\IHtmlDocument\obj\Debug\IHtmlDocument.csproj.FileListAbsolute.txt

     文件        975  2015-01-23 20:25  IHtmlDocument\IHtmlDocument\obj\Debug\IHtmlDocument.csproj.GenerateResource.Cache

     文件       5905  2015-01-23 16:29  IHtmlDocument\IHtmlDocument\obj\Debug\IHtmlDocument.csprojResolveAssemblyReference.cache

     文件      21504  2015-01-23 20:25  IHtmlDocument\IHtmlDocument\obj\Debug\IHtmlDocument.exe

     文件        180  2015-01-23 20:25  IHtmlDocument\IHtmlDocument\obj\Debug\IHtmlDocument.Form1.resources

     文件      36352  2015-01-23 20:25  IHtmlDocument\IHtmlDocument\obj\Debug\IHtmlDocument.pdb

     文件        180  2015-01-23 17:12  IHtmlDocument\IHtmlDocument\obj\Debug\IHtmlDocument.Properties.Resources.resources

     文件       1161  2015-01-23 02:43  IHtmlDocument\IHtmlDocument\obj\Debug\IHtmlDocument2.csproj.FileListAbsolute.txt

     文件        975  2015-01-23 01:15  IHtmlDocument\IHtmlDocument\obj\Debug\IHtmlDocument2.csproj.GenerateResource.Cache

     文件       5216  2015-01-23 01:42  IHtmlDocument\IHtmlDocument\obj\Debug\IHtmlDocument2.csprojResolveAssemblyReference.cache

     文件      15360  2015-01-23 02:42  IHtmlDocument\IHtmlDocument\obj\Debug\IHtmlDocument2.exe

............此处省略28个文件信息

评论

共有 条评论

相关资源