Solved

Opening IE and saving page as jpeg or htm with VB

Posted on 2004-08-10
10
355 Views
Last Modified: 2010-05-02
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.
0
Comment
Question by:Plastic_1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
10 Comments
 
LVL 14

Expert Comment

by:aelatik
ID: 11762865
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
 

Author Comment

by:Plastic_1
ID: 11763215
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
 
LVL 14

Expert Comment

by:aelatik
ID: 11763562
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
SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

 

Author Comment

by:Plastic_1
ID: 11763663
Where do I insert the second part of code into the orginal code?  
0
 
LVL 14

Accepted Solution

by:
aelatik earned 400 total points
ID: 11763690
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
 

Author Comment

by:Plastic_1
ID: 11764215
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
 
LVL 14

Expert Comment

by:aelatik
ID: 11764310
How do you know it loaded from the cache ?
0
 

Author Comment

by:Plastic_1
ID: 11764421
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
 
LVL 14

Expert Comment

by:aelatik
ID: 11764433
I already thought you looked at the time stamp on the picture :-)
0
 

Author Comment

by:Plastic_1
ID: 11764448
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

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month7 days, 17 hours left to enroll

617 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question