3.1: Using ColdFusion

Create the Scripts

We'll be creating two different scripts to interact with screen-scraper via ColdFusion. The first will be using ColdFusion tags, and the second will be using ColdFusion script. Each of these scripts will invoke our scraping session remotely and pass in a value for the TEXT_TO_SUBMIT session variable.

If you have not already configured ColdFusion to run with screen-scraper, now is a good time to setup ColdFusion.

Tags Method

Create a new ColdFusion script on your computer, and paste the following code into it:

<html>
<head>
<title>ColdFusion Tag Example</title>
</head>
<body>
<cfobject
action = "create"
type = "java"
class = "com.screenscraper.scraper.RemoteScrapingSession"
name = "RemoteScrapingSession">
<cfset remoteSession = RemoteScrapingSession.init("Hello World","localhost",8778)>
<cfset remoteSession.setVariable( "TEXT_TO_SUBMIT", "Hi everybody!" )>
<cfset remoteSession.scrape()>
<cfset test = remoteSession.getVariable("FORM_SUBMITTED_TEXT")>
<cfset remoteSession.disconnect()>
<cfoutput>
textReturned: #test#
</cfoutput>
</body>
</html>

Script Method

If you prefer using ColdFusion script to program, you can use the following code instead of the code we give above:

<html>
<head>
<title>ColdFusion Script Example</title>
</head>

<body>
<cfscript>
 RemoteScrapingSession = CreateObject("java","com.screenscraper.scraper.RemoteScrapingSession");
 remoteSession = RemoteScrapingSession.init("Hello World","localhost",8778);
 remoteSession.setVariable( "TEXT_TO_SUBMIT", "Hi everybody!" );
 remoteSession.scrape();
 test = remoteSession.getVariable( "FORM_SUBMITTED_TEXT" );
 remoteSession.disconnect();
</cfscript>
<cfoutput>
textReturned: #test#
</cfoutput>
</body>
</html>

Script Description

You can probably follow the logic but for clarity let's take a moment to look at it. This script creates a RemoteScrapingSession, initializes it to be connected to the Hello World scraping session, sets the TEXT_TO_SUBMIT session variable, then scrapes the page and explicitly disconnects.

Running the Script

OK, we're ready to give our ColdFusion script a try. Start screen-scraper running in server mode. If you've succeeded in starting up the server go ahead and access your ColdFusion script from your browser. After a short pause you should see textReturned: Hi everybody! appear.