Show Contents / Index / Search

Get Text from a Web Page

This sample program shows how to get text from a Web page document that's open in Reflection 2008. To do this, we get a Web control object to access the Web page document and then use the XPATH to identify the Web element (text) on the page, as follows:

IWebElement WebElement = WebDocument.GetElement("HTML/BODY/TABLE/TBODY/TR[1]/TD[1]")

You can also use the ID to work with Web elements. For an example, see Integrate Web and Host Data.

To create a Web page document

  1. Using a text editor, such as Notepad, create a new text file called table.htm.
  2. Copy this HTML Table Code, paste it into the text file, and then save the file.

    In Reflection 2008, create a new Web page document and type the file path to table.htm in the URL box. For example, if you saved the file to

    C:\Users\user_name\Documents\Attachmate\Reflection\

    type the following path (in one continuous string):

    file:///C:/Users/user_name/Documents/Attachmate/Reflection/table.htm

  3. Name the Web page document Webtable.urlx and save it to the same location as "table.htm."
  4. Quit, and then restart Reflection 2008.
  5. In Visual Studio, create a new Console Application project. In the New Project dialog box, type Get a Web Object in the Name box.
  6. Select the Create directory for solution box, click Browse to select your API projects folder (for example, C:\MyProjects), and then click OK.
  7. In Solution Explorer, add the class assemblies. (For instructions, see Create an API Project.)
  8. Copy the code from Get a Web Object, paste it to the Program.cs tab, and then edit the path in the code to match the path to which you saved Webtable.urlx.
  9. Build the application (Build > Rebuild Solution) and then run it (Debug > Start Without Debugging).

A console box should appear with the text extracted from Webtable.urlx: "The currency conversion rate from Canadian to U.S. Dollar: [number]. Press any key to continue..."