How To Extract This Image From The Web

Maury1704

New Member
Joined
Jan 13, 2016
Messages
24
Hello everyone from Maurizio
My problem is this:
On an Excel sheet I am downloading all the Weather data from a Web page including the Type images (Img)
And so far so good.
But I would like to be able to download an image (Dl) classified as (i)
I'm trying them all but I'm not going back
You would kindly be able to help me understand where I'm wrong.
Thanks
VBA Code:
Sub Previsioni_Tabella()
On Error Resume Next

Dim CollA As Object, CollB As Object
Dim cSrc As String, cIW As Single
Dim IE

X = Foglio1.Range("G1").Value & ""
Y = Foglio1.Range("I1").Value & ""
'
myURL = "https://www.worldweatheronline.com/" & X & "/" & Y & "" & "/it.aspx#pills-tomorrow"
Set IE = CreateObject("internetExplorer.Application")
'
With IE
    .navigate myURL
    .Visible = False                    'meglio TRUE
'    .Visible = True
    Do While .Busy: DoEvents: Loop
    Do While .readyState <> 4: DoEvents: Loop
End With

Do
    DoEvents
    If Timer > myStart + 2 Or Timer < myStart Then Exit Do
Loop
'
'Importa la tabella "10 Day Weather Forecast"
rbase = "A38"                                                    '<<< Dove scrivere
Set CollA = IE.document.getElementBydd("col-4")     'id della tabella
Call RangeClear(Range(rbase).Resize(12, 9))                     'Cancella contenuto della tabella
'col-4
'wi-moon-first-quarter
Set CollB = CollA.getElementsBydl("row")
ccnt = 99: j = 0
On Error Resume Next
For I = 0 To CollB.Length - 1
    ccl = CollB(I).className
    If InStr(1, "ZcZc" & ccl, "col-sm-12", vbTextCompare) > 0 Or ccnt < 8 Then
        If InStr(1, "ZcZc" & ccl, "col-sm-12", vbTextCompare) > 0 Then ccnt = 0: j = j + 1
        If InStr(1, "ZcZc" & ccl, "col-sm-12", vbTextCompare) = 0 Then
            Range(rbase).Offset(j - 1, ccnt).Value = CollB(I).innerText
            cSrc = "": cIW = 0
            cSrc = CollB(I).getElementsByTagName("img")(0).getAttribute("src")
            If cSrc <> "" Then
                Call GetShapeFromWeb("https:" & cSrc, Range(rbase).Offset(j - 1, ccnt))
                cIW = ActiveSheet.Shapes(ActiveSheet.Shapes.Count).Width
                With Range(rbase).Offset(j - 1, ccnt)
                    .ColumnWidth = 10
                    .ColumnWidth = cIW / .Width * 10
                    .EntireRow.RowHeight = cIW
                End With
            End If
            ccnt = ccnt + 1
        End If
    End If
Next I
On Error GoTo 0

'Chiusura IE
IE.Quit
Set IE = Nothing

'Call Weather_Immagini
End Sub

Sub RangeClear(ByRef myRan As Range)
Dim Shp As Shape
'
myRan.ClearContents
myRan.EntireRow.AutoFit
For Each Shp In ActiveSheet.Shapes
    If Shp.Type = msoPicture Or Shp.Type = msoLinkedPicture Then
        If Not Application.Intersect(Shp.TopLeftCell, myRan) Is Nothing Then
            Shp.Delete
        End If
    End If
Next Shp
End Sub
 

Attachments

  • Image_Da_Scaricare.JPG
    Image_Da_Scaricare.JPG
    8.9 KB · Views: 10

Excel Facts

How to calculate loan payments in Excel?
Use the PMT function: =PMT(5%/12,60,-25000) is for a $25,000 loan, 5% annual interest, 60 month loan.
Hi Logit Sorry about the Gaf
But I didn't think to include this part as well; But I Do It Now Thanks
Greetings from A.Maurizio

VBA Code:
Dim Campo As Range
Dim Forma As Object
Dim I As Long


Sub GetShapeFromWeb(strShpUrl As String, rngTarget As Range)

On Error Resume Next
With rngTarget.Parent
.Pictures.Insert strShpUrl
.Shapes(.Shapes.Count).Left = rngTarget.Left '= 1
.Shapes(.Shapes.Count).Top = rngTarget.Top '= 1
.Shapes(.Shapes.Count).Height = rngTarget.Height
.Shapes(.Shapes.Count).Width = rngTarget.Width
End With
End Sub

Sub Weather_Immagini()
On Error Resume Next
Dim I As Long

For I = 1 To 1
Call GetShapeFromWeb(Foglio1.Range("B38").Value, Foglio1.Range("C14"))
'Call GetShapeFromWeb(Foglio1.Range("B9").Value, Foglio1.Range("A5"))
'Call GetShapeFromWeb(Foglio1.Range("B10").Value, Foglio1.Range("B5"))
'Call GetShapeFromWeb(Foglio1.Range("B11").Value, Foglio1.Range("C5"))
'Call GetShapeFromWeb(Foglio1.Range("B12").Value, Foglio1.Range("D5"))
'Call GetShapeFromWeb(Foglio1.Range("B13").Value, Foglio1.Range("E5"))
'Call GetShapeFromWeb(Foglio1.Range("B14").Value, Foglio1.Range("F5"))
'Call GetShapeFromWeb(Foglio1.Range("B15").Value, Foglio1.Range("G5"))

'https://www.meteolive.it/resources/images_for_css/icone-previsioni/sunny.png
Next I
Call InsertPic
End Sub

Sub InsertPic()
On Error Resume Next
Set myDocument = Worksheets(1)
For Each s In myDocument.Shapes

Select Case s.Type
    
Case msoEmbeddedOLEObject, _
msoLinkedOLEObject, _
msoOLEControlObject, _
msoLinkedPicture, msoPicture
            
s.scaleleft 100, msoTrue
s.scaleTop 100, msoTrue

Case Else

End Select
Next

For Each Pict In ActiveSheet.Shapes

Foglio1.Range("A2").Value = ActiveSheet.Shapes
'Range("A4").Value = Forma
Pict.Height = 40
Pict.Width = 40

'Pict.Left = 100
'Pict.Top = 100
Next

End Sub
 
Upvote 0
HI - I had a quick look at the website. It turns out that the moon phase images are not actually images - they're using an icon font, so they behave like text and not images. My suggestion is perhaps just get some moon phase imagery from another site (I think you can get the moon phases in the Unicode set) and then just check from the class name what phase the moon is expected to be in. For example, for tonight, the class name for Barcelona's moon phase is: wi wi-moon-first-quarter.

Hope that helps.
 
Upvote 0
Hi Dan_W
First of all, thank you for your explanation on the matter:
But then also those four images you see in the photo inserted in this post
Would they be Icons?
Therefore: If I wanted to receive in their place as well calls in the reality of the site.
Then go fishing in my sub folder.
It would be enough for me to write something like this, addressed to a cell (innerHTML) or it would be better to write (responseText)
Thanks Infinite for all the help you will be able to give me
I renew my greetings to you and to the whole Forum
By A.Maurizio



Altre_Image_Weather.JPG
 
Upvote 0
Hi. Those four are very likely images. If all you want are the images, there some really good websites with free options that will save you time and effort from webscraping - have you looked at those?

Also, there a plenty of free web APIs for weather forecasts. For example, theweather.com have an API, but even better (and easier) they have a weather widget which produces for you a URL that gives you a free rolling forecast with custom options - I made the one below as an example in less than 10 seconds... what do you think? (link)

1634244309674.png
 
Upvote 0
Hi Dan_W
First I would like to apologize to you for my delay in replying to your post.
A generous thank you for offering me your support and link
Which among other things is truly beautiful.
But my question was just asked to try to understand what the heck those images were made of and how they were to be treated. That's all.
But since I've been working on it for a while
Without making a spider out of the hole.
Pensop just that I will change Structure and I will definitely go to your link.
Thank you so much for everything you are fantastic too.
Sincere greetings from A.Maurizio
 
Upvote 0
You're very welcome, and no need to apologise. Thank you for getting back to me, though - I do sometimes wonder if I've been of any help. :)
In terms of your question as to why you couldn't extract it as an image - it's a fair question - I just had to do some digging through the Developer section of Chrome, and then the CSS code for the website to work out the answer - that it was simply an icon font.

You can think of it like Windings for the web (or webdings, in fact!). Those moon phases that you were looking at are, quite simply, understood by the browser too be nothing more than characters in a font set. Font Awesome is an example of this, as are the Google Material Icons. As you can see from this screen capture, you have the option of using the icons as an SVG, a PNG, or an icon font (and it provides the relevant html/css code to use it).

1634591901834.png


Separately, if you want to get into webscraping more, I'd strongly recommend taking some time to learn about the developer tools available in the different browsers (Firefox even have a special developer edition of their browser!) - there is a lot of functionality available - and I'm still learning it myself.
 
Upvote 0
Hi Dan_W thanks for your further clarification on the matter. I understand a lot from your suggestion. Thank you so much now I'll start studying and then I'll let you know.

If I dare, I would like to ask you this again. taking as a starting point the beginning of my program inserted in my first post. I would like to know this: If I wanted to take advantage of the opening of a Google type browser. not using Internet Explorer (ie) but Open "Get" how could I get even the first data of my link by continuing the structure (oggCol. getelementclassname (".....") etc ....!
 
Upvote 0
Hi. Those four are very likely images. If all you want are the images, there some really good websites with free options that will save you time and effort from webscraping - have you looked at those?

Also, there a plenty of free web APIs for weather forecasts. For example, theweather.com have an API, but even better (and easier) they have a weather widget which produces for you a URL that gives you a free rolling forecast with custom options - I made the one below as an example in less than 10 seconds... what do you think? (link)

View attachment 49096
I was able to generate the code I needed from the link you provided, but how can get this to display on my excel spreadsheet...as the intended image?
 
Upvote 0

Forum statistics

Threads
1,214,945
Messages
6,122,397
Members
449,081
Latest member
JAMES KECULAH

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