国产探花免费观看_亚洲丰满少妇自慰呻吟_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);

  }

  }

  }

  }

  }

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

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 凌源市| 闸北区| 东莞市| 平昌县| 右玉县| 称多县| 睢宁县| 晋中市| 广河县| 红安县| 曲周县| 永安市| 临江市| 会同县| 巴林右旗| 乌恰县| 镇雄县| 收藏| 开远市| 彰化县| 墨玉县| 洛川县| 神农架林区| 荔浦县| 霞浦县| 昌黎县| 定陶县| 临潭县| 汾阳市| 龙门县| 三河市| 嵊泗县| 南澳县| 阳新县| 凯里市| 湛江市| 东兰县| 千阳县| 万载县| 九龙县| 苏尼特左旗|