C# Automating Internet Explorer #2 창 열고 코드 가져오기

준비 과정

Reference
  • SHDocVw : Microsoft Internet Controls
  • MSHTML: Microsoft HTML Object Library

따라하기

프로젝트 생성

 

Microsoft Internet Controls Reference 추가

 

 

Microsoft HTML Object Library 추가

 

코딩
using mshtml;
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 WATIE_02
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var IE = new SHDocVw.InternetExplorer();
            IE.Visible = true;

            object oURL = "http://docs.whiteat.com";
            IE.Navigate2(ref oURL);

            // 페이지가 완전히 열릴 때까지 기다림
            while (IE.Busy == true || IE.ReadyState != SHDocVw.tagREADYSTATE.READYSTATE_COMPLETE)
            {
                System.Threading.Thread.Sleep(100);
            }
            HTMLDocument doc = IE.Document;
            this.lblTitle.Text = doc.title;
            this.lblURL.Text = doc.url;
            this.textBox1.Text = doc.body.parentElement.outerHTML;

        }
    }
}

 

결과

버튼을 클릭할 때마다 새로운 Internet Explorer 창이 열리며 코드를 가져 옵니다.

답글 남기기

이메일 주소는 공개되지 않습니다. 필수 필드는 *로 표시됩니다