How to scrap the phone number in a determined URL

FranciscoRo

New Member
Joined
Feb 27, 2023
Messages
4
Office Version
  1. 2021
Platform
  1. Windows
1) I want to scrap the phone number which appears in this URL: https://www.idealista.com/inmueble/96599356/
The phone is 607176984.
Up to now I have been able to get the other data that I need, from that URL .

2 Using Chrome, I get this code of the URL (the lines that are related to this case)

<div class="ide-box-contact module-contact-gray contact-data-container ">
<h2 class="txt-big txt-bold mb-small">
Anunciante
</h2>
<div id="contact-phones-container" class="hidden-contact-phones no-form">
<a role="button" aria-label="contact phone" class="icon-phone hidden-contact-phones_link" href="">
<span class="hidden-contact-phones_text">Ver teléfono</span>
<span class="animation_circle">
<span class="circle"></span>
<span class="circle"></span>
<span class="circle"></span>
</span>
</a>
</div>
<div class="professional-name">
<div class="name">
Particular
</div>
<span class="particular">
<span class="icon-block"></span>

3)I have written this code in Excel VBA

Code:
EnSub detalles_de_cada_trastero()
ActiveSheet.Select
hoja_actual = ActiveSheet.Name   
Application.ScreenUpdating = False
    
Dim XMLPage As New MSXML2.XMLHTTP60
Dim htmldoc As New MSHTML.HTMLDocument
Dim htmlim As MSHTML.IHTMLElement
Dim htmlims As MSHTML.IHTMLElementCollection
Dim url As String
    
url = "https://www.idealista.com/inmueble/96599356/"   
    
XMLPage.Open "Get", url_corregida, False
XMLPage.setRequestHeader "Content-Type", "text/xml" On Error Resume Next XMLPage.send
htmldoc.body.innerHTML = XMLPage.responseText       
# First: I try with this code. It doesn't work       
       Set htmlims = htmldoc.getElementsByClassName("hidden-contact-phones_text")
        For Each htmlim In htmlims
            Sheets("hoja_actual").Cells(Fila, 12).Value = htmlim.innerText       
        texto = htmlim.innerText   ' what I get is  "Ver teléfono"       
        Next htmlim
====================================================
  
#  'Second: I try with this code
        Set htmlims = htmldoc.getElementsByClassName("icon-phone hidden-contact-phones_formatted-phone _mobilePhone")
        For Each htmlim In htmlims '*************************The control doesn't enter in this For-Next.   It jumps it             
        texto = htmlim.getAttribute("href")       
        'Sheets("hoja_actual").Cells(Fila, 12).Value = htmlim.innerText       
        Next htmlim       
        '===============================================================
# 'Third: I try this
        
        texto = htmldoc.getElementsByClassName("icon-phone hidden-contact-phones_formatted-phone _mobilePhone")  'Gives "nothing"
        
        texto = htmldoc.getElementsByClassName("icon-phone hidden-contact-phones_formatted-phone _mobilePhone").Item
        texto = htmldoc.getElementsByClassName("icon-phone hidden-contact-phones_formatted-phone _mobilePhone").toString         
        '===============================================================

#       'Fourth: I try this
        
        texto = htmldoc.getElementById("contact-phones-container")
        Set htmlims = htmldoc.getElementById("contact-phones-container")    'Error!     
        For Each htmlim In htmlims           
           texto_1 = htmlim.Children(0).innerText  'sale profesonal'
            texto = htmlim.getAttribute("href") 
            texto_2 = htmlim.Children(1).innerText         
        Next

Any help will be wellcome







Any help will be wellcome
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand
Where in the HTML code is the phone number? I don't see it.
 
Upvote 0

Forum statistics

Threads
1,223,164
Messages
6,170,444
Members
452,326
Latest member
johnshaji

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top