VBA Web scraping for image src's

messer5740

New Member
Joined
Aug 13, 2020
Messages
2
Office Version
  1. 2013
Platform
  1. Windows
Hi all,

I am looking to make a program which I can web scrape HTML src's with. My code enters info into a couple text boxes and runs an external query to generate graphs. I want to take the graph src, download it, and insert it into my excel doc. I am having a hell of a time getting the src scraped however. Think you can give me a hand?

Here is my code:

VBA Code:
Private Declare PtrSafe 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


Sub openScrubLineLossCharts()

    Dim ie As Object
    Dim dateToday As Date
    Dim userElement As Variant
    Dim imgsrc As Object
    Dim dlpath As Variant
    Dim previewImg As Variant
    Dim URL As String
    Dim html As HTMLDocument
    Dim ElementCol As Object
    Dim Link As Object
    Dim ecol As Long
    Dim objElement As IHTMLElement
    
    
    URL = "http://botprodweb/LineLossReview/"
    
    Set ie = CreateObject("internetexplorer.application") 'internet explorer
   
    
    
    'ensures website is properly loaded
    With ie
        ie.Visible = True '78687968796867876878976876True when testing, False when active. Allows view of changes made to website
    
        ie.Navigate "http://botprodweb/LineLossReview/default.aspx" 'Line loss query website

        Do While .Busy
            DoEvents
        Loop

        Do While .ReadyState <> 4
            DoEvents
        Loop
    End With

'
' etc
'
'
' BELOW IS WHERE I NEED HELP AT!


    Dim doc As HTMLDocument
    Set doc = ie.Document
    Dim sDD As String
    sDD = doc.getElementsByTagName("img")(src)
    '25 line loss chart
    Dim ActiveDocument As Object
    Set ActiveDocument = ie
    
    'Set objElement = ActiveDocument.all.tags("head").Item(0)
    
   
Dim intCount As Integer

'For Each objElement In ActiveDocument.body.all
    intCount = intCount + 1
    objElement.ID = objElement.tagName & intCount
'Next
 


    
    
        dlpath = "J:\BP&S_Operations\Daily Multi-Tool\Line Loss Chart Photo Dump\"
    URLDownloadToFile 0, src, dlpath & "25.png", 0, 0

End Sub

I know it really needs cleaned up, but I need to make it work first.
 

Some videos you may like

Excel Facts

What does custom number format of ;;; mean?
Three semi-colons will hide the value in the cell. Although most people use white font instead.

Watch MrExcel Video

Forum statistics

Threads
1,122,980
Messages
5,599,160
Members
414,295
Latest member
Dolenhil

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
Top