Opening IE and saving page as jpeg or htm with VB

I need a VB sript to open IE to a specific webpage (weather.com) and then save this page as a jpeg or htm (weather.jpeg or weather.htm) and then close IE.  Reasoning behind this is I have users that need to view current weather info but do not have access to internet. This will be displayed on local intranet.   If I have a script then I can set up a scheduled task to run the script and save/replace the image at set intervals.  This will update the intranet webpage giving users what they need without giving any access to the internet or messing with user rights.  Any help would be appreciated.
Plastic_1Asked:
Who is Participating?
 
aelatikConnect With a Mentor Commented:
This is it :

Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Const IMAGE_FILE As String = "http://image.weather.com/web/radar/us_ric_closeradar_medium_usen.jpg"

Private Sub Form_Load()
    ' I am passing the date and time after the URL to avoid loading from cache
    Call URLDownloadToFile(0, IMAGE_FILE & "?ID=" & Now, "c:\temp.jpg", 0, 0)
End Sub

Ignore the previous post, that is another method...
0
 
aelatikCommented:
VBSCRIPT can't handle this, it does not interact with a GUI. But if you wish to do something in VB maybe i can help.
What you want "save as jpg" is possible. But the machine that runs the scheduled task may not run a screensaver or anything that blocks the screen. In that case you could use the following :


>>>>>>>>>>>>>>>
Put a picturebox on a VB form and paste the following code :

Private Declare Sub keybd_event Lib "User32" (ByVal bVk As Byte, ByVal bScan As Byte, ByVal dwFlags As Long, ByVal dwExtraInfo As Long)

Private Sub Form_Load()
    TakePicture "http://www.weather.com/", "c:\weather.jpg"
End Sub

Private Function TakePicture(URL As String, Filename As String)
    Dim IE As Object
    Set IE = CreateObject("internetexplorer.application")
        IE.fullscreen = True
        IE.AddressBar = False
        IE.navigate URL
        While IE.busy: DoEvents: Wend
        IE.Visible = True
        IE.StatusBar = False
        IE.ToolBar = False
        While IE.busy: DoEvents: Wend
        keybd_event &H2C, 0, 0, 0
        keybd_event &H2C, 1, 0, 0
        keybd_event &H2C, 1, 0, 0
        DoEvents
        Picture1.Picture = Clipboard.GetData
        IE.Quit
    Set IE = Nothing
        SavePicture Picture1.Picture, Filename
End Function

If this doesn't work out for you then you have to consider extracting the weather text or pictures out of the website.
Just let me know,

Elatik , A
0
 
Plastic_1Author Commented:
The code works fine but as you mentioned maybe just extracting the radar picture would be nice.
Is it possible to just extract the radar picture from http://www.weather.com/weather/local/USVA0143?from=search_current
0
Cloud Class® Course: Microsoft Windows 7 Basic

This introductory course to Windows 7 environment will teach you about working with the Windows operating system. You will learn about basic functions including start menu; the desktop; managing files, folders, and libraries.

 
aelatikCommented:
Private Declare Function URLDownloadToFile Lib "urlmon" Alias "URLDownloadToFileA" (ByVal pCaller As Long, ByVal szURL As String, ByVal szFileName As String, ByVal dwReserved As Long, ByVal lpfnCB As Long) As Long
Private Const IMAGE_FILE As String = "http://image.weather.com/web/radar/us_ric_closeradar_medium_usen.jpg"

Private Sub Form_Load()
    ' I am passing the date and time after the URL to avoid loading from cache
    Call URLDownloadToFile(0, IMAGE_FILE & "?ID=" & Now, "c:\temp.jpg", 0, 0)
End Sub
0
 
Plastic_1Author Commented:
Where do I insert the second part of code into the orginal code?  
0
 
Plastic_1Author Commented:
The date and time is not passing correctly because on the second and third runs of the script it pulls the image from cache.

I will up the point because you have been very helpful on this.......
0
 
aelatikCommented:
How do you know it loaded from the cache ?
0
 
Plastic_1Author Commented:
I assumed (which is not the appropriate thing to do) that the time stamp from weather.com on the bottom of radar display would stay current with time.  That is incorrect.  It seems they only udate the radar picutre every 20-30 minutes.

Many thanks for your help.  
0
 
aelatikCommented:
I already thought you looked at the time stamp on the picture :-)
0
 
Plastic_1Author Commented:
I did look at the time stamp but it did not change with consecutive runs so I assumed it was loading from cache.  That was incorrect.

I increased the points to 400 and accepted your answer.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.