Modify Last Response

    // With events, we can modify the Last Response before extractors are run
    // on it.  Perhaps we care about line breaks

    import com.screenscraper.events.*;
    import com.screenscraper.events.scrapeablefile.*;
    import com.screenscraper.scraper.*;

    // Setup a call on scrapeable files named "Details" to insert a
    // <br /> tag everywhere there is a line break character
    EventHandler handler = new EventHandler(){
        public String getHandlerName()
        {
            return "Update last response with line breaks";
        }

        public Object handleEvent(EventFireTime fireTime, ScrapeableFileEventData data)
        {
            ScrapingSession session = data.getSession();
            session.logInfo("Swapping out line breaks in the response for <br /> tags");

            // We know for the event time this will trigger that this is a String
            // and is the response data (post tidy) from the server
            String response = data.getLastReturnValue();

            response = response.replaceAll("(?s)\r?\n", "<br />\n");

            // Return the new value, which will be used as the last response
            return response;
        }
    };

    // Set the event to be fired at a specific time.  The documentation
    // (as seen in the completion popup) tells us for this fire time
    // the return value will be used as the response data
    session.addEventCallback(ScrapeableFileEventFireTime.AfterHttpRequest, handler);

    session.scrapeFile("Manually Scraped");