Invoking screen-scraper from ColdFusion
Overview
To interact with screen-scraper from ColdFusion we will make use of ColdFusion's ability to implement Java classes. The ColdFusion server can execute Java code but needs to be configured first.
screen-scraper needs to be running as a server before invoking it externally.
Configuring ColdFusion for Java
These steps assume that the server is running on the local machine and default setup. Some consideration might need to be given if you have changed these settings.
- Access the ColdFusion adminstration interface at http://127.0.0.1:8500/CFIDE/administrator/index.cfm and enter the administrator password.
- Under Server Settings on the left, select the Java and JVM link.
- Add the screen-scraper.jar to the class path.
You can find the jar where screen-scraper was installed. If it was installed on the local Windows machine then the classpath might look like this:
- Make sure to click the Submit changes button and restart the ColdFusion service.
- After the service has been restarted check to make sure that the screen-scraper.jar is now in the server's classpath by selecting the Settings Summary link under the Server Settings section.
Interacting with screen-scraper
Now that the server will be able to load the Java class and interact with the screen-scraper server through it, you now need to learn the methods and objects. As you are really interacting through Java you will need to read the section on Invoking screen-scraper from Java to learn about the methods and classes.
Example
The following is an example of a .cfm file that creates a RemoteScrapingSession object, calls the scrape method and processes the results. The scraping session to be invoked is called test and we will be outputing a session variable, TEST that we have saved in screen-scraper.
<html>
<head>
<title>A Cold Fusion Page</title>
</head>
<body>
<cfobject
action = "create"
type = "java"
class = "com.screenscraper.scraper.RemoteScrapingSession"
name = "RemoteScrapingSession">
<cfset remoteSession = RemoteScrapingSession.init("test","localhost",8778)>
<cfset remoteSession.scrape()>
<cfset test = remoteSession.getVariable("TEST")>
<cfoutput>
#test#
</cfoutput>
<cfset remoteSession.disconnect()>
</cfobject>
</body>
</html>
For another example of interacting with screen-scraper via ColdFusion please see Tutorial 4: Scraping a Shopping Site from External Programs.