A PHP script interacts with screen-scraper via a PHP class called RemoteScrapingSession. You can utilize this class by including the file remote_scraping_session.php (found in the misc/php directory of your screen-scraper installation) within your PHP script.
screen-scraper needs to be running as a server before invoking screen-scraper from a PHP script.
The following is a reference for all of the methods found in the RemoteScrapingSession class.
Currently only Strings, DataRecords, and DataSets can be accessed by this method.
Calling this method will only have an effect if it's done before calling the scrape method. If this value is set to true, after the scrape method is called, program flow will return immediately, but the scraping session will still be running in screen-scraper.
This feature is only available to Enterprise editions of screen-scraper.
By creating a special PHP class, your code can handle extracted data as it is being scraped instead of after the scrape is finished. That means, you will not need to wait until the scraping session has finished before getting access to the extracted data.
We recommend calling the class DataReceiver.
The DataReceiver class needs to contain the following method (you can add other methods as needed to process the data but this one is particular).
Once you have created the DataReceiver class containing the receiveData method it must be incorporated into the RemoteScrapingSession using the setDataReceiver method. Here are other methods that allow you to control the flow of real time information.
On the screen-scraper side, whenever you'd like to send data from screen-scraper back to your code, you simply invoke the session.sendDataToClient method. Data sent through this method will be processed through the receiveData method.
As a specific example, let's suppose you've created a scraping session that extracts product records from a shopping web site. As each product record is being scraped, you might simply output them to a CSV file, but you decide instead that you'd like to insert them into your database, and determine that it would be best for you to write your own code to perform the database insertion. On the screen-scraper side, in your scraping session, you might have a script that contains the following:
You set up this script to be invoked After each pattern match for the extractor pattern that pulls the product information. For example, the extractor pattern might get the price, title, and weight of the product. Because the script is being invoked After each pattern match, the current dataRecord object will hold all of that information. You invoke session.sendDataToClient so that each record can be processed by your code as it gets extracted.
In your PHP code you create a class that implements the receiveData( $key, $value ). You create an instance of this class and pass it to your RemoteScrapingSession object so that you can process each of the product records as they get extracted. Your DataReceiver class implementation might look something like this:
You would instantiate the class and set it on your session like so:
Each time you invoke session.sendDataToClient in screen-scraper, there will be a corresponding method call made to your receiveData method, which will allow you to handle each of the data pieces individually.
For other examples of using the PHP driver please see Tutorial 3: Extending Hello World and Tutorial 4: Scraping an E-commerce Site from External Programs.