Thursday, February 25, 2010

Accessing live cricket score from C# Win Forms Application - Using Screen Scrapping technique.

Quite often during the crucial stages of a cricket match, we might want to refresh the browser frequently, in order to get the latest score. And more importantly we need to stay in the browser window.

This can be done programmatically, through the following steps.

1. Launch an embedded web browser in a C# win forms application.

2. Supply the URL of the page which publishes the latest cricket score.

3. Capture the entire HTMLDOM of that page.

4. Identify the HTML element which displays the score (that is changing) and save the index of that HTML element (the index is unique for all the HTML elements).

5. Load the entire HTMLDOM once again and Get the element by index (already saved).

6. Querying for the text at that element gives you the latest score.

7. Run the steps 5, 6 on a timer (say 7 seconds to keep refreshing the page.)

Note: The HTML markup of the page should not change while scrapping.

Code Snippets:

Steps -1, 2

image

Steps -3, 4

 image

Steps 5,6,7

image

This technique can be ideally used to ‘scrape’ weather updates, Stock rates etc, which keeps changing frequently.

No comments: