0

I have this HTML, and I'm trying scrape the values behind data-v-88f004c6 after "Compra:" and after "Venta:"

<div class="info-tc" data-v-88f004c6>
  <span data-v-88f004c6>Tipo de cambio del dólar hoy en Perú</span>   
  <span data-v-88f004c6>
    <i aria-hidden="true" class="fa fa-info-circle i-help" data-v-88f004c6></i>
  </span>
  <span data-v-88f004c6>Compra: 
    <strong data-v-88f004c6></strong>
  </span>
  <span data-v-88f004c6>Venta: 
    <strong data-v-88f004c6></strong>
  </span>
</div>

When I bring up the developer tools from Chrome I can see that the values appear like this (3.199 and 3.237):

<div class="info-tc" data-v-88f004c6="">
  <span data-v-88f004c6="">Tipo de cambio del dólar hoy en Perú</span>&nbsp;&nbsp;&nbsp;
  <span data-v-88f004c6="">
    <i aria-hidden="true" class="fa fa-info-circle i-help" data-v-88f004c6=""></i>&nbsp;
  </span>
  <span data-v-88f004c6="">Compra:&nbsp;
    <strong data-v-88f004c6="">3.199</strong>
  </span>&nbsp;&nbsp;
  <span data-v-88f004c6="">Venta:&nbsp;
    <strong data-v-88f004c6="">3.237</strong>
  </span>
</div>

However when I scrape the values using Excel I get symbols like this for the prices.

Tipo de cambio del dólar hoy en Perú    Compra:   Venta:Â

I'm using a code like this to scrape the web:

    Set GetRawHTML = New HTMLDocument
    With CreateObject("WINHTTP.WinHTTPRequest.5.1")
        .Open "GET", urlWebSite, False
        .send
        GetRawHTML = .responseText
    End With
    kambistafx = GetRawHTML.body.innerHTML
    fxprice = kambistafx .getElementsByClassName("info-tc").Item(0).innerText

What should I do to scrape those values?

3
  • Are you trying to get the table containing those value you have mentioned in your post? Have you tried using IE? Commented Mar 26, 2018 at 18:28
  • IE is another method for scraping data from Excel? I haven't tried it. But it's weird that function doesn't work, it's the first time I have a problem with it. Commented Mar 26, 2018 at 20:37
  • 1
    It's the first time for you to encounter such trouble because you never scraped any dynamically generated items. However, be it winhttp, xmlhttp, or serverxmlhttp, they can't handle javascript heavy items. So, the best choice for you in this case is to choose any browser simulator. Commented Mar 27, 2018 at 4:04

1 Answer 1

1

I did this with selenium basic

CSS selectors

#__layout span:nth-child(2) +*") 'compra
#__layout span:nth-child(3) +*") 'venta 

These are contracted versions of full selectors which were:

#__layout > div > main > section.banner > div.central-section > div.col.paddingTop2 > section > div > span:nth-child(2) > strong
#__layout > div > main > section.banner > div.central-section > div.col.paddingTop2 > section > div > span:nth-child(3) > strong

Example CSS query:

CSS query

Source page values

Source


Code:

Option Explicit
Public Sub GetInfoSel()
    Dim d As WebDriver, keys As New keys
    Set d = New ChromeDriver
    Const URL = "https://kambista.com/"

    With d
        .Start "Chrome"
        .Get URL
          Debug.Print .FindElementByCss("#__layout span:nth-child(2) +*").Text 'compra
          Debug.Print .FindElementByCss("#__layout span:nth-child(3) +*").Text  'venta
        .Quit
    End With
End Sub

Note:

After installing Selenium basic and opening excel you need to add a reference via VBE > Tools > References > Selenium type library

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

2 Comments

Hi, Did you try this please? I went to the effort of answering it for you.
Yes, but not on my work terminal. I can't install selenium on that computer.

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.