国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > HTML > 正文

用C#從,IE瀏覽器中獲取HTML文檔

2020-03-24 15:50:05
字體:
來源:轉載
供稿:網友

  Create a console application in any version of Visual Studio using .Net version 1|2|3|3.5.

  Add two Com object references which will allow us to manipulate IE.

  用 Visual Studio 的任意版本建立一個控制臺程序。

  添加2個COM對象引用用來操作IE

用C#從IE瀏覽器中獲取HTML文檔

  Note the code sample below does not require the using directive for the objects, so just add the code as is.

  Then find the instances of IE and extract the document:

  添加下面代碼

  打開IE獲取HTML文檔

  SHDocVw.ShellWindows shellWindows

  = new SHDocVw.ShellWindowsClass();

  string filename;

  foreach (SHDocVw.InternetExplorer ie in shellWindows)

  {

  filename

  = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

  if (filename.Equals("iexplore"))

  {

  Console.WriteLine("Web Site  : {0}", ie.LocationURL);

  mshtml.IHTMLDocument2 htmlDoc

  = ie.Document as mshtml.IHTMLDocument2;

  Console.WriteLine("  Document Snippet: {0}",

  ( ( htmlDoc != null ) ? htmlDoc.body.outerHTML.Substring(0, 40)

  : "***Failed***" ));

  Console.WriteLine("{0}{0}", Environment.NewLine);

  }

  }

  Here is a screen-shot of the output:

  程序截圖:


  代碼:

  using System;

  using System.Collections.Generic;

  using System.Text;

  using System.IO;

  namespace ConsoleApplic

小調網電影下載[www.aikan.tv/special/xiaodiaowang/]ation1

  {

  class Program

  {

  static void Main(string[] args)

  {

  SHDocVw.ShellWindows shellWindows = new SHDocVw.ShellWindowsClass();

  string filename;

  foreach (SHDocVw.InternetExplorer ie in shellWindows)

  {

  filename = Path.GetFileNameWithoutExtension(ie.FullName).ToLower();

  if (filename.Equals("iexplore"))

  {

  Console.WriteLine("Web Site  : {0}", ie.LocationURL);

  mshtml.IHTMLDocument2 htmlDoc = ie.Document as mshtml.IHTMLDocument2;

  Console.WriteLine("  文件 Snippet: {0}", ((htmlDoc != null) ? htmlDoc.body.outerHTML.Substring(0, 40) : "***Failed***"));

  Console.WriteLine("{0}{0}", Environment.NewLine);

  }

  }

  }

  }

  }

鄭重聲明:本文版權歸原作者所有,轉載文章僅為傳播更多信息之目的,如作者信息標記有誤,請第一時間聯系我們修改或刪除,多謝。

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 区。| 绿春县| 闽侯县| 寿宁县| 东宁县| 建始县| 申扎县| 呼伦贝尔市| 温宿县| 余江县| 克拉玛依市| 隆林| 沙坪坝区| 山东省| 轮台县| 侯马市| 广饶县| 霍山县| 新巴尔虎右旗| 张家界市| 雷山县| 泉州市| 云和县| 辽阳市| 会宁县| 东乌| 尼玛县| 偏关县| 岗巴县| 章丘市| 收藏| 明溪县| 利辛县| 南通市| 古丈县| 望城县| 原平市| 龙泉市| 新密市| 永平县| 沂源县|