Visual Web Ripper Logo Visual Web Ripper Logo
Welcome Guest Search | Active Topics | Log In | Register

Tag as favorite
Using input parameters in web scraping projects
Sequentum Support
#1 Posted : Wednesday, September 01, 2010 11:00:41 PM

Groups: Administrators
Joined: 4/10/2010
Posts: 1,239
Location: Sydney, Australia
Input parameters can be supplied to web scraping projects and are available to all scripts within the project.

Input parameters can be used in conjunction with a project initialization script to initialize a web scraping project for a specific environment, such as setting the database connection to a test database when running in a test environment, and setting the connection to a production database when runnning in a production environment.

Specific input parameters can be defined in a web scraping project. All defined parameters can have a default value.



A parameter entry screen will appear when you run a web scraping project from the Visual Web Ripper designer if the project has any defined input parameters.



If you run a web scraping project from the command line you can supply any number of input parameters, both already defined parameters and new parameters. All the parameters will be available to scripts in the project. If you don't supply a value for a defined parameter, the default value will be used.



At this time, you cannot supply input parameters to a project that is run using the build-in scheduler.

Example 1 - Using input parameters to change the destination data source

This example shows how to configure a project initialization script to use input parameters to change the destination data source. The script will only change the database connection properties supplied, so if a username is not supplied for exmaple, the default username will be used.

A project initialization script is added in the project options advanced tab.



The following script checks if an input parameter exists and then sets the corresponding database connection property.



Example 2 - Setting a FixedValue content element with the value of an input parameter

You can use a simple Content Transformation script to set the content element with the value of an input parameter.

Code:
using System;
using VisualWebRipper.Internal.SimpleHtmlParser;
using VisualWebRipper;
public class Script
{
    public static string TransformContent(WrContentTransformationArguments args)
    {
        try
        {            
            return args.InputParameters["par1"];
        }
        catch(Exception exp)
        {            
            args.WriteDebug(exp.Message);
            return "Custom script error";
        }
    }
}



Example 3 - Setting a FormField content element with the value of an input parameter

You can use a simple Input Transformation script to set FormField content element with the value of an input parameter.

Code:
using System;
using VisualWebRipper.Internal.SimpleHtmlParser;
using VisualWebRipper;
public class Script
{
    //See help for a definition of WrInputTransformationArguments.
    public static string TransformInput(WrInputTransformationArguments args)
    {
        try
        {        
            return args.InputParameters["par1"];
        }
        catch(Exception exp)
        {            
            args.WriteDebug(exp.Message);
            return "Custom script error";
        }
    }
}


Example 4 - Setting the project start URL to the value of an input parameter

You can use a simple project initialization script to set the project start URL to the value of an input parameter.

Code:
using System;
using mshtml;
using VisualWebRipper;
public class Script
{
    //See help for a definition of WrProjectInitializeArguments.
    public static bool InitializeProject(WrProjectInitializeArguments args)
    {
        try
        {
            if(args.InputParameters.ContainsParameter("url"))
                args.Project.StartUrl = args.InputParameters["url"];

            return true;
        }
        catch(Exception exp)
        {
            args.WriteDebug(exp.Message);
            return false;
        }
    }
}


osperez
#2 Posted : Friday, October 22, 2010 9:22:56 PM
Groups: Registered
Joined: 10/22/2010
Posts: 2
Where can I type the project initialization script?
Sequentum Support
#3 Posted : Tuesday, October 26, 2010 8:26:45 PM

Groups: Administrators
Joined: 4/10/2010
Posts: 1,239
Location: Sydney, Australia
Please see the image close to this text in the article above:

A project initialization script is added in the project options advanced tab.
wimg
#4 Posted : Monday, April 18, 2011 8:31:38 AM
Groups: Registered
Joined: 4/18/2011
Posts: 1
Is it possible to use the parameters as input for the filename of a database name for a 'redirect' template ? The idea is to let the system login, then have it go to different URLs based on the data in the database (CSV-file). This works fine, except I want to use different input files.
Sequentum Support
#5 Posted : Wednesday, April 20, 2011 6:04:29 AM

Groups: Administrators
Joined: 4/10/2010
Posts: 1,239
Location: Sydney, Australia
You can use a script to generate input values, so it's possible, but not easy. The script would then access the input parameter and read the appropriate data from a database.

See this topic in the manual for more information:

http://manual.visualwebr...ault.aspx?manual_id=3752
Users browsing this topic
Guest
Tag as favorite
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.

Powered by YAF 1.9.4 RC1 | YAF © 2003-2009, Yet Another Forum.NET
This page was generated in 0.117 seconds.