Show Contents / Index / Search

Get a Web Object Program

using System;

using System.Collections.Generic;

using System.Text;

using Attachmate.Reflection.Web.Msie;

using Attachmate.Reflection.Framework;

namespace GetTextFromWebPage

{

class Program

{

static void Main(string[] args)

{

Attachmate.Reflection.Framework.Application reflectionApplication = MyReflection.CreateApplication("Reflection");

if (reflectionApplication != null)

{

//Create the Web control.

IWebControl webControl = (IWebControl)reflectionApplication.CreateControl(@"C:\Users\[user name]\Documents\Attachmate\Reflection\Webtable.urlx");

if (webControl != null)

{

IWebDocument webDocument = webControl.Document;

if (webDocument != null)

{

//Get the Web element by using the xpath.

IWebElement webElement = webDocument.GetElement("HTML/BODY/TABLE/TBODY/TR[1]/TD[1]");

if (webElement != null)

{

string conversionRate = webElement.InnerText;

Console.WriteLine("The currency conversion rate from Canadian to U.S. dollars: " + conversionRate);

}

else

Console.WriteLine("Can not find the webElement. Please check the xpath for the webElement.");

}

else

Console.WriteLine("Fatal error. Check the Reflection 2008 installation.");

}

else

Console.WriteLine("Can not create the Web control. Check the Web session file path.");

}

else

Console.WriteLine("Failed to get Application object. Check the Reflection 2008 installation and the API port number.");

}

}

}