Solved

Opening IE and saving page as jpeg or htm with VB

Posted on 2004-08-10
10
352 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
  • 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
3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

 

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

809 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