Skip to content

Instantly share code, notes, and snippets.

@xicalango
Created October 16, 2013 20:44

Revisions

  1. xicalango created this gist Oct 16, 2013.
    28 changes: 28 additions & 0 deletions getpage.c
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    #include <stdio.h>
    #include <stdlib.h>


    int main(int argc, char** argv)
    {

    const char* wget_command = "wget ""%s"" -O ""%s""";
    char run_command[1000] = {0};

    if( argc != 3 )
    {
    printf("Call %s <url> <outputfile>\n", argv[0]);
    return EXIT_FAILURE;
    }

    int result = snprintf( run_command, 1000, wget_command, argv[1], argv[2] );

    if( result < 0 || result > 1000 )
    {
    perror("parameters too long");
    }

    system( run_command );


    return EXIT_SUCCESS;
    }
    14 changes: 14 additions & 0 deletions getpage.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    #import the module needed
    import urllib2
    import sys

    #make a request to the server, and place response in a variable
    response = urllib2.urlopen(sys.argv[1])
    #response object is a file like object

    #read the data from the response into a string
    html_string = response.read()

    #write to output
    with open(sys.argv[2], "w") as f:
    f.write(html_string)