0

I would like to get the value EURO for next link

www.banxico.org.mx/tipcamb

Really I don't have any idea.

I tried with this, but it does not work.

clear
$url = "https://www.banxico.org.mx/tipcamb/main.do?page=tip&idioma=sp";
$r = Invoke-WebRequest $url;

$table2 = $r.ParsedHtml.getElementsByTagName("table") | Select -first 5;
$table2 | select -ExpandProperty innertext;
1
  • 2
    Try to get the exchange rate from their API instead of scraping a HTML page. Commented Oct 13, 2022 at 6:13

1 Answer 1

1

As a general tip, don't do web scraping when there is an API available. Therefore, my answer will cover the basic API use, if that's one way that interest you.

As for the API, You can obtain a token here: https://www.banxico.org.mx/SieAPIRest/service/v1/token (don't use the example one, it won't work, you need to generate one)

Also, if you look at the top page, you'll see "Series de tiempo", which contains the following information, which you'll need later.

# SF43707  Reservas Internacionales.
# SF61745  Tasa objetivo
# SF60648  TIIE a 28 días.
# SF60649  TIIE a 91 días.
# SF60633  Cetes a 28 días.
# SF43718  Pesos por Dólar. FIX.
# SF60653  Pesos por Dólar. Fecha de liquidación.
# SF46410  Euro.
# SF46406  Yen japonés.
# SF46407  Libra esterlina.
# SF60632  Dólar Canadiense.
# SP68257  Valor de UDIS.

From there, find what you want to do from the API page

https://www.banxico.org.mx/SieAPIRest/service/v1/

or test directly in the Swagger UI

https://www.banxico.org.mx/SieAPIRest/service/swagger-ui.html#/Series

Now, if you wanted to Powershell all that and get the value of a few series for the day, you can use :

# Replace with the token you generated
$Headers = @{Headers = @{'Bmx-Token' = 'YOUR_TOKEN_HERE' }}
$ApiUrl = 'https://www.banxico.org.mx/SieAPIRest/service/v1'
$StartDate = (Get-date).AddDays(-1).ToString('yyyy-MM-dd')
$EndDate = $StartDate
$Result = Invoke-RestMethod -Uri "$ApiUrl/series/SF43718,SF46410,SF46406,SF60632/datos/$StartDate/$EndDate" @Headers
$Result.bmx.series | Select idSerie,@{'n'='dato';e={$_.datos.dato}}

Now, if you want to do get different data, you'll need to play around with their API.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.