0

I am new to google app script. I learnt that I can use UrlFetchApp.fetch("website address") to get the information from a simple webpage and then I can abstract the information subsequently.

However, if a webpage requires fill up some information and click a button to proceed to the result page. can I repeat the steps using google app script such that I can abstract the information on the result page? Thanks.

Example to illustrate the steps :

  1. go to a webpage : https://usa.visa.com/support/consumer/travel-support/exchange-rate-calculator.html/

  2. fill up information: as highlighted by red circles

    input data

  3. after clicking the "Calculate Exchange Rates" button, the result page is shown:

    result page

Follow up discussion:

The below link is working and it will return the exchange rate I want to read in browser.

https://usa.visa.com/support/consumer/travel-support/exchange-rate-calculator.html/?fromCurr=JPY&toCurr=USD&fee=1.95&exchangedate=01%2F05%2F2018&submitButton=Calculate+Exchange+Rates

I then made a script as below:

but it return "You don't have permission to access". Is there any way out?

// Input parameters
  var VisaYear = '2018';
  var VisaMonth = '01';
  var VisaDay = '05'; 
  var toCurr = 'USD';  
  var fromCurr = 'JPY';
  var fee = 1.95;

  // download front page information  
  var root = "https://usa.visa.com/support/consumer/travel-support/exchange-rate-calculator.html"
  var sub1 = '/?fromCurr='
  var sub2 = '&toCurr='
  var sub3 = '&fee='
  var sub4 = '&exchangedate='
  var sub5 = '%2F'
  var sub6 = '%2F'
  var sub7 = '&submitButton=Calculate+Exchange+Rates'
  var RESOURCE_URL = root + sub1 + fromCurr +sub2 + toCurr + sub3 + fee + sub4 + VisaMonth + sub5 + VisaDay + sub6 + VisaYear + sub7   
  var data = UrlFetchApp.fetch(RESOURCE_URL,{muteHttpExceptions: true})
  var rc = data.getResponseCode();



  if (rc == 200) {
    folder.createFile(FileName[1], data) 
warsur
  • 19
  • 5
  • Here is a reference for [URL Fetch Service](https://developers.google.com/apps-script/reference/url-fetch/). You will be able to fetch urls from simple website. Also, check out [External APIs](https://developers.google.com/apps-script/guides/services/external) where you can use Google Apps Script to interact with API's all over the web. Example are provided on how to work on different types of API's. For further information, visit this [SO post](https://stackoverflow.com/questions/22282344/google-app-script-extracting-data-from-website). – MαπμQμαπkγVπ.0 Jan 05 '18 at 11:40
  • Hi MαπμQμαπkγVπ.0, Thanks for your enlightenment. I finally found the required link. Thanks. fromCurr=JPY&toCurr=USD&fee=1.95&exchangedate=01%2F05%2F2018&submitButton=Calculate+Exchange+Rates – warsur Jan 06 '18 at 00:36
  • The Stack Snippet tool should only be used with executable JavaScript/HTML/CSS. Google Apps Script is not executable. – Rubén Jan 06 '18 at 02:51
  • Hi Rubén, I amended. – warsur Jan 06 '18 at 02:59

1 Answers1

0

In answer to your question, No. It is not possible to do what you are asking, because by and large websites protect against automatic remote completion of forms. In this particular case why not use the current formula in Google sheets? Here is a list of currency symbols

=GoogleFinance("CURRENCY:GBPEUR")
Jason Allshorn
  • 1,625
  • 1
  • 18
  • 27
  • Hi Jason, thanks. I didn't make it clear what I trying to do. I am thinking about whether I can write a script to check which credit card (visa vs master) is cheaper? when I use in abroad. – warsur Jan 06 '18 at 01:50
  • Hi Jason, you are right. It seems that I cannot get the right answer. Even though I tried to fetch the original link (https://usa.visa.com/support/consumer/travel-support/exchange-rate-calculator.html). – warsur Jan 07 '18 at 17:44
  • I wonder if you could use the card or bank's api. For example I think this one gets Visa's exchanges rates. https://developer.visa.com/capabilities/foreign_exchange – Jason Allshorn Jan 08 '18 at 08:48