get descrption from web item

User avatar
sal21
GoldLounger
Posts: 3316
Joined: 26 Apr 2010, 17:36

get descrption from web item

Post by sal21 »

i use this code to get info from html page:

url of current page: https://www.tuttitalia.it/banche/classifica/1/

Code: Select all

Sub ExtractDetails(doc)
    
    Dim R As Integer, TS As Object, COLONNE As Integer, RIGHE As Integer
    
    Do While Not IE.readyState = READYSTATE_COMPLETE
    Loop
    
    Set TS = doc.getElementsByTagName("table")
    
    COLONNE = TS(2).Rows(1).Cells.Length
    
    RIGHE = TS(2).Rows.Length
    
    For R = 1 To RIGHE - 1
        Debug.Print UCase(TS(2).Rows(R).Cells(0).innerText)        
        Debug.Print TS(2).Rows(R).Cells(1).innerText
        Debug.Print TS(2).Rows(R).Cells(2).innerText
    Next R
    
End Sub
now how to get the info from cells(0)?

See image attached
You do not have the required permissions to view the files attached to this post.

YasserKhalil
PlatinumLounger
Posts: 4265
Joined: 31 Aug 2016, 09:02

Re: get descrption from web item

Post by YasserKhalil »

The code is already working for me. Can you explain in details what's the problem and the desired ouptu?

User avatar
sal21
GoldLounger
Posts: 3316
Joined: 26 Apr 2010, 17:36

Re: get descrption from web item

Post by sal21 »

YasserKhalil wrote:
18 Sep 2020, 09:50
The code is already working for me. Can you explain in details what's the problem and the desired ouptu?
i need the href text in my case i need: 74-unione-di-banche-italiane

User avatar
sal21
GoldLounger
Posts: 3316
Joined: 26 Apr 2010, 17:36

Re: get descrption from web item

Post by sal21 »

sal21 wrote:
18 Sep 2020, 09:55
YasserKhalil wrote:
18 Sep 2020, 09:50
The code is already working for me. Can you explain in details what's the problem and the desired ouptu?
i need the href text in my case i need: 74-unione-di-banche-italiane

see the label with the little arrow on the bottom left, in image attached

User avatar
HansV
Administrator
Posts: 69376
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: get descrption from web item

Post by HansV »

You can use the Split function with "/" as delimiter to split the innertext.
The text you want is the next to last element of the array.
Regards,
Hans

User avatar
sal21
GoldLounger
Posts: 3316
Joined: 26 Apr 2010, 17:36

Re: get descrption from web item

Post by sal21 »

HansV wrote:
18 Sep 2020, 09:58
You can use the Split function with "/" as delimiter to split the innertext.
The text you want is the next to last element of the array.
buit i need only the href value...

href="/banche/74-unione-di-banche-italiane/

User avatar
HansV
Administrator
Posts: 69376
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: get descrption from web item

Post by HansV »

Code: Select all

    Dim arr() As String
    ...
        Debug.Print UCase(TS(2).Rows(R).Cells(0).innerText)        
        arr = Split(TS(2).Rows(R).Cells(0).innerText, "/")
        Debug.Print arr(UBound(arr) - 1)
    ...
Regards,
Hans

YasserKhalil
PlatinumLounger
Posts: 4265
Joined: 31 Aug 2016, 09:02

Re: get descrption from web item

Post by YasserKhalil »

You can also use it like that

Code: Select all

Debug.Print UCase(TS(2).Rows(r).Cells(0).getElementsByTagName("a")(1).innerText)

User avatar
sal21
GoldLounger
Posts: 3316
Joined: 26 Apr 2010, 17:36

Re: get descrption from web item

Post by sal21 »

<A HREF="/BANCHE/55-INTESA-SANPAOLO/"><IMG WIDTH="16" HEIGHT="16" CLASS="AO" ALT="LOGO" SRC="HTTPS://IMAGES.TUTTITALIA.IT/BANCHE/S_I ... ></A><SPAN CLASS="XQ"> &NBSP; &NBSP;1.</SPAN> <A HREF="/BANCHE/55-INTESA-SANPAOLO/">INTESA SANPAOLO</A>

NO innerText...

i need 55-INTESA-SANPAOLO, from href!

note:
the lenght of href value is variable

i get entire href line from:

debug.print UCase(TS(2).Rows(R).Cells(0).innerHTML)

YasserKhalil
PlatinumLounger
Posts: 4265
Joined: 31 Aug 2016, 09:02

Re: get descrption from web item

Post by YasserKhalil »

Try this

Code: Select all

                Dim sHREF As String
                sHREF = UCase(TS(2).Rows(r).Cells(0).getElementsByTagName("a")(1).getAttribute("href"))
                Debug.Print Split(sHREF, "/")(UBound(Split(sHREF, "/")) - 1)