<link href='https://www.blogger.com/dyn-css/authorization.css?targetBlogID=6549724036207680656&amp;zx=de779642-2f7e-4395-a5a7-135811de2179' rel='stylesheet'/>

2015年6月6日土曜日

C#でIEを自動制御しよう (13) 表示しているページタイトル&URLを取得する

■表示しているページタイトル&URLを取得する

InternetExplorerオブジェクトのLocationNameプロパティでページのタイトルを、LocationURLプロパティでページのURLを取得できます。下記サンプルコードは、デバッグ実行するとYahoo!ファイナンスのページを開き、ページのタイトル&URLを、VSの出力ウィンドウに出力します。

サンプルコード

public void ShowCurrentPageTitleAndURL()
{
var IE = new SHDocVw.InternetExplorer();
IE.Visible = true;
object URL = "http://finance.yahoo.co.jp/";
IE.Navigate2(ref URL);
IE.Wait();
Debug.WriteLine(IE.LocationName + " : " + IE.LocationURL);
}
view raw test.cs hosted with ❤ by GitHub