Quantcast
Channel: Hot Weekly Questions - Web Applications Stack Exchange
Viewing all articles
Browse latest Browse all 9632

Create new sheet with a "template" based on cell value

$
0
0

I'm trying to do run some stats on the AFL (Australian Football league) here in Australia and want to get some better understanding on players form based on some key stats.= In order to do this, I would like to check if a URL exists and returns response code 200 and if so then create a new spreadsheet with the query ID of the URL. A URL looks like this https://www.footywire.com/afl/footy/fts_match_statistics?mid=9721

My editable spreadsheet is here.

What I have done so far is create a script to check if a URL (Column A) exists, the response of that is stored in Column B.

The code I use to check the URL is

​function HTTPResponse( uri )
{
    var response_code ;
    try {
        response_code = UrlFetchApp .fetch( uri ) .getResponseCode() .toString() ;
    }
    catch( error ) {
        response_code = error .toString() .match( / returned code (\d\d\d)\./ )[1] ;
    }
    finally {
        return response_code;
    }
}

What I​'m trying to do is:
If the response_code is 200, then create a new spreadsheet with the bold highlighted part of the URL (e.g. 9721). In that new sheet in A1 then the formula

=IMPORTHTML("https://www.footywire.com/afl/footy/fts_match_statistics?mid=9721&sby=14#t1","table",12).

Where the URL is identical to the checked URL initially.

I thought I can check if the repsonse_code is 200 then add a new sheet, but somehow that ends up in an error all the time.
If anyone can point me in the right direction that would be great.


Viewing all articles
Browse latest Browse all 9632

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>