Alpha API
Overview
When writing scripts within screen-scraper, there are a number of objects and methods available to you. You can view the stable objects and classes available to scripts in the API section of our documentation. This sections only documents those methods that are in a current alpha release. You are welcome to use them but know that they are prone to change. We always work for backwards compatibility of stable features but with alpha features we will not guarantee compatibility until they appear in a stable version.
Alpha methods and objects are only available if you have screen-scraper upgrade to unstable versions. We don't guarantee that the methods will not change after their introduction if improvements are required, desired, or purposes change.
The examples are given using Interpreted Java as the scripting language. This is in accordance with the stable API.
scrapeableFile
Changes to scrapeableFile
scrapeableFile.applyXPathExpression
void scrapeableFile.applyXPathExpression ( String xPathExpression ) (professional and enterprise editions only)
Description
Applies an XPath expression to the current HTML response. If tidying the response failed this method will also fail.
Parameters
- xPathExpression A valid XPath expression.
Return Values
An XmlNode. See example for usage.
Change Log
Version |
Description |
6.0.1a |
Available in Professional and Enterprise editions. |
Examples
Apply an XPath Expression
outputNode( node, indent )
{
// e.g., in the case of a <td> tag the getName call
// will return the text "td".
if( node.getName()!=null )
{
openTag = new StringBuffer();
openTag.append( indent + " <" + node.getName() );
// The getAttributes method returns an ArrayList of
// KeyValue objects.
for( iter = node.getAttributes().iterator(); iter.hasNext(); )
{
attribute = iter.next();
openTag.append( " " + attribute.getKey() + "=\"" + attribute.getValue() + "\"" );
}
openTag.append( ">" );
session.log( openTag.toString() );
}
// e.g., in the case of <td>foo</td> the getValue method
// call will return the text "foo".
if( node.getValue()!=null )
{
session.log( indent + " " + node.getValue() );
}
// getChildNodes returns an ArrayList of XmlNode objects.
for( iter = node.getChildNodes().iterator(); iter.hasNext(); )
{
childNode = iter.next();
outputNode( childNode, indent + "--" );
}
if( node.getName()!=null )
{
session.log( indent + " </" + node.getName() + ">" );
}
}
// Match all <td> tags.
node = scrapeableFile.applyXPathExpression( "//td" );
// Note that there is an equivalent sutil
// method call: sutil.applyXPathExpression( String content, String expression )
// If the content parameter doesn't contain a well-formed
// block of XML an exception will be thrown.
outputNode( node, "" );