Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 282525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T05:17:46+00:00 2026-05-12T05:17:46+00:00

I would like to create a program that will enter a string into the

  • 0

I would like to create a program that will enter a string into the text box on a site like Google (without using their public API) and then submit the form and grab the results. Is this possible? Grabbing the results will require the use of HTML scraping I would assume, but how would I enter data into the text field and submit the form? Would I be forced to use a public API? Is something like this just not feasible? Would I have to figure out query strings/parameters?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T05:17:47+00:00Added an answer on May 12, 2026 at 5:17 am

    Theory

    What I would do is create a little program that can automatically submit any form data to any place and come back with the results. This is easy to do in Java with HTTPUnit. The task goes like this:

    • Connect to the web server.
    • Parse the page.
    • Get the first form on the page.
    • Fill in the form data.
    • Submit the form.
    • Read (and parse) the results.

    The solution you pick will depend on a variety of factors, including:

    • Whether you need to emulate JavaScript
    • What you need to do with the data afterwards
    • What languages with which you are proficient
    • Application speed (is this for one query or 100,000?)
    • How soon the application needs to be working
    • Is it a one off, or will it have to be maintained?

    For example, you could try the following applications to submit the data for you:

    • Lynx
    • curl
    • wget

    Then grep (awk, or sed) the resulting web page(s).

    Another trick when screen scraping is to download a sample HTML file and parse it manually in vi (or VIM). Save the keystrokes to a file and then whenever you run the query, apply those keystrokes to the resulting web page(s) to extract the data. This solution is not maintainable, nor 100% reliable (but screen scraping from a website seldom is). It works and is fast.

    Example

    A semi-generic Java class to submit website forms (specifically dealing with logging into a website) is below, in the hopes that it might be useful. Do not use it for evil.

    import java.io.FileInputStream;
    
    import java.util.Enumeration;
    import java.util.Hashtable;  
    import java.util.Properties; 
    
    import com.meterware.httpunit.GetMethodWebRequest;
    import com.meterware.httpunit.SubmitButton;       
    import com.meterware.httpunit.WebClient;          
    import com.meterware.httpunit.WebConversation;    
    import com.meterware.httpunit.WebForm;            
    import com.meterware.httpunit.WebLink;            
    import com.meterware.httpunit.WebRequest;         
    import com.meterware.httpunit.WebResponse;        
    
    public class FormElements extends Properties
    {                                           
      private static final String FORM_URL = "form.url";
      private static final String FORM_ACTION = "form.action";
    
      /** These are properly provided property parameters. */
      private static final String FORM_PARAM = "form.param.";
    
      /** These are property parameters that are required; must have values. */
      private static final String FORM_REQUIRED = "form.required.";            
    
      private Hashtable fields = new Hashtable( 10 );
    
      private WebConversation webConversation;
    
      public FormElements()
      {                    
      }                    
    
      /**
       * Retrieves the HTML page, populates the form data, then sends the
       * information to the server.                                      
       */                                                                
      public void run()                                                  
        throws Exception                                                 
      {                                                                  
        WebResponse response = receive();                                
        WebForm form = getWebForm( response );                           
    
        populate( form );
    
        form.submit();
      }               
    
      protected WebResponse receive()
        throws Exception             
      {                              
        WebConversation webConversation = getWebConversation();
        GetMethodWebRequest request = getGetMethodWebRequest();
    
        // Fake the User-Agent so the site thinks that encryption is supported.
        //                                                                     
        request.setHeaderField( "User-Agent",                                  
          "Mozilla/5.0 (X11; U; Linux i686; en-US; rv\\:1.7.3) Gecko/20040913" );
    
        return webConversation.getResponse( request );
      }                                               
    
      protected void populate( WebForm form )
        throws Exception                     
      {                                      
        // First set all the .param variables.
        //                                    
        setParamVariables( form );            
    
        // Next, set the required variables.
        //                                  
        setRequiredVariables( form );       
      }                                     
    
      protected void setParamVariables( WebForm form )
        throws Exception                              
      {                                               
        for( Enumeration e = propertyNames(); e.hasMoreElements(); )
        {                                                           
          String property = (String)(e.nextElement());              
    
          if( property.startsWith( FORM_PARAM ) )
          {                                      
            String fieldName = getProperty( property );
            String propertyName = property.substring( FORM_PARAM.length() );
            String fieldValue = getField( propertyName );                   
    
            // Skip blank fields (most likely, this is a blank last name, which
            // means the form wants a full name).                              
            //                                                                 
            if( "".equals( fieldName ) )                                       
              continue;                                                        
    
            // If this is the first name, and the last name parameter is blank,
            // then append the last name field to the first name field.        
            //                                                                 
            if( "first_name".equals( propertyName ) &&                         
                "".equals( getProperty( FORM_PARAM + "last_name" ) ) )         
              fieldValue += " " + getField( "last_name" );                     
    
            showSet( fieldName, fieldValue );
            form.setParameter( fieldName, fieldValue );
          }                                            
        }                                              
      }                                                
    
      protected void setRequiredVariables( WebForm form )
        throws Exception                                 
      {                                                  
        for( Enumeration e = propertyNames(); e.hasMoreElements(); )
        {                                                           
          String property = (String)(e.nextElement());              
    
          if( property.startsWith( FORM_REQUIRED ) )
          {                                         
            String fieldValue = getProperty( property );
            String fieldName = property.substring( FORM_REQUIRED.length() );
    
            // If the field starts with a ~, then copy the field.
            //                                                   
            if( fieldValue.startsWith( "~" ) )                   
            {                                                    
              String copyProp = fieldValue.substring( 1, fieldValue.length() );
              copyProp = getProperty( copyProp );                              
    
              // Since the parameters have been copied into the form, we can   
              // eke out the duplicate values.                                 
              //                                                               
              fieldValue = form.getParameterValue( copyProp );                 
            }                                                                  
    
            showSet( fieldName, fieldValue );
            form.setParameter( fieldName, fieldValue );
          }                                            
        }                                              
      }                                                
    
      private void showSet( String fieldName, String fieldValue )
      {                                                          
        System.out.print( "<p class='setting'>" );               
        System.out.print( fieldName );                           
        System.out.print( " = " );                               
        System.out.print( fieldValue );                          
        System.out.println( "</p>" );                            
      }                                                          
    
      private WebForm getWebForm( WebResponse response )
        throws Exception                                
      {                                                 
        WebForm[] forms = response.getForms();          
        String action = getProperty( FORM_ACTION );     
    
        // Not supposed to break out of a for-loop, but it makes the code easy ...
        //                                                                        
        for( int i = forms.length - 1; i >= 0; i-- )                              
          if( forms[ i ].getAction().equalsIgnoreCase( action ) )                 
            return forms[ i ];                                                    
    
        // Sadly, no form was found.
        //                          
        throw new Exception();      
      }                             
    
      private GetMethodWebRequest getGetMethodWebRequest()
      {
        return new GetMethodWebRequest( getProperty( FORM_URL ) );
      }
    
      private WebConversation getWebConversation()
      {
        if( this.webConversation == null )
          this.webConversation = new WebConversation();
    
        return this.webConversation;
      }
    
      public void setField( String field, String value )
      {
        Hashtable fields = getFields();
        fields.put( field, value );
      }
    
      private String getField( String field )
      {
        Hashtable<String, String> fields = getFields();
        String result = fields.get( field );
    
        return result == null ? "" : result;
      }
    
      private Hashtable getFields()
      {
        return this.fields;
      }
    
      public static void main( String args[] )
        throws Exception
      {
        FormElements formElements = new FormElements();
    
        formElements.setField( "first_name", args[1] );
        formElements.setField( "last_name", args[2] );
        formElements.setField( "email", args[3] );
        formElements.setField( "comments",  args[4] );
    
        FileInputStream fis = new FileInputStream( args[0] );
        formElements.load( fis );
        fis.close();
    
        formElements.run();
      }
    }
    

    An example properties files would look like:

    $ cat com.mellon.properties
    
    form.url=https://www.mellon.com/contact/index.cfm
    form.action=index.cfm
    form.param.first_name=name
    form.param.last_name=
    form.param.email=emailhome
    form.param.comments=comments
    
    # Submit Button
    #form.submit=submit
    
    # Required Fields
    #
    form.required.to=zzwebmaster
    form.required.phone=555-555-1212
    form.required.besttime=5 to 7pm
    

    Run it similar to the following (substitute the path to HTTPUnit and the FormElements class for $CLASSPATH):

    java -cp $CLASSPATH FormElements com.mellon.properties "John" "Doe" "John.Doe@gmail.com" "To whom it may concern  ..."
    

    Legality

    Another answer mentioned that it might violate terms of use. Check into that first, before you spend any time looking into a technical solution. Extremely good advice.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 154k
  • Answers 154k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You're definitely on the right track: $(document).ready(function() { $('.box-content2 a').click(function()… May 12, 2026 at 10:33 am
  • Editorial Team
    Editorial Team added an answer Try calling Table<TEntity>.InsertOnSubmit. May 12, 2026 at 10:33 am
  • Editorial Team
    Editorial Team added an answer I think what you are missing is the component scan… May 12, 2026 at 10:33 am

Related Questions

My application will have a per machine (not per user) Startup shortcut. I can
I'm currently writing some intranet web application where people could submit to admins requests
I am working on a program where I want to be able to add
Not as in can't find the answer on stackoverflow, but as in can't see
I built an excel model used to analyze real estate transactions. I would like

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.