Parse HTML code, Copy Image, Paste back in Excel

mrmmickle1

Well-known Member
Joined
May 11, 2012
Messages
2,461
I am attempting to navigate to a webpage using IE. I have been successful at getting to the appropriate webpage. However, I would like to open a link within the webpage in the browser in another window(Which is an image). Copy the image then paste it back into excel. I have been successful at opening the webpage using a Userform. Here is the code for this first aspect:

Rich (BB code):
Sub Anthro()
Application.ScreenUpdating = False
Set ie = CreateObject("InternetExplorer.Application")
With ie
.Visible = True
strURL = "http://www.anthropologie.com/anthro/product/shopnew-clothes/" & TextBox1.Value & ".jsp"
.navigate strURL
Application.ScreenUpdating = True
End With

End Sub

The user input number for example:

If the user inputs the number 25423310 into the txtbox then it navigates to a certain webpage.
On this webpage and all other webpages where different #'s are used are very similar. The number (25423310) is always used to identify an image. However it has more characters. For example the image is always on line 30 of the HTML code. On this example the HTML code lists the image as:

<metaproperty="og:image" content="http://images.anthropologie.com/is/image/Anthropologie/25423310_065_b?$redesign-appcat$"/>

The number used in the txtbox to naviagete to the URL Ex: 25423310) is always within line 30 of code in HTML. Is it possible to run a query or parse this line of code and direct ie to open this image in a new window then copy and paste it based on the criteria of the user input? Ex. 25423310?

I found a few threads that have some code attempting to parse HTML data. Here is one that I feel could aid my cause. Is anyone able to help me solve this problem?

Rich (BB code):
Sub PropInfo() 
    Dim appIE As SHDocVw.InternetExplorer 
    Set appIE = New SHDocVw.InternetExplorer 
    Dim varTables, varTable 
    Dim varRows, varRow 
    Dim varCells, varCell 
    Dim lngRow As Long, lngColumn As Long 
    Dim txt As String 
     
     
     'OPEN INTERNET EXPLORER, GO TO WEBPAGE
    appIE.Visible = True 
    appIE.navigate "http://gisims2.miamidade.gov/MyHome/proptext.asp" 
     
    Do While appIE.Busy: DoEvents:  Loop 
        Do While appIE.readyState <> 4: DoEvents: Loop 
             
             'POPULATE USER FIELDS, AND PERFORM A QUERY
            With appIE.document.frmNavigation 
                .Item("bytool").Value = "ADDR" 'Search by' dropdown
                .Item("bytool").onchange 
                .Item("stnum").Value = "2417" 'house #' field
                .Item("stdir").Value = "" 
                .Item("stname").Value = "ponce de leon" 'street  name' field
                .Item("sttype").Value = "BLVD" 'street type' field
                .submit 
            End With 
            Do While appIE.Busy: DoEvents:  Loop 
                Do While appIE.readyState <> 4: DoEvents: Loop 
                    appIE.document.all.Item 
                    Call appIE.document.parentWindow.execScript("doAddrSearch()", "Javascript") 
                    Do While appIE.Busy: DoEvents:  Loop 
                        Do While appIE.readyState <> 4: DoEvents: Loop 
                             'SCRAPE WEBPAGE FOR INFO
                            For i = 0 To appIE.document.getElementsByTagName("TD").Length - 1 
                                Set s = appIE.document.getElementsByTagName("TD").Item(i) 
                                txt = s.getAttribute("innerText") 
                                If txt <> "" Then 
                                    If InStr(1, txt, "CLUC") > 0 Then 
                                        Worksheets("Sheet1").Range("DropOff").Value = txt 
                                        Exit For 
                                    End If 
                                End If 
                            Next 
                            Set s = Nothing 
                             
                             
                        End Sub

Any help with this problem would be much appreciated!!!
 
Last edited:

Excel Facts

Format cells as date
Select range and press Ctrl+Shift+3 to format cells as date. (Shift 3 is the # sign which sort of looks like a small calendar).
Can you post an actual link to a page you would open, what would you then click on?
 
Upvote 0
Can you post an actual link to a page you would open, what would you then click on?


The URL is :
http://www.anthropologie.com/anthro/product/shopnew-clothes/25423310.jsp

You would click on the link below the picture that says "Open in New Window"

Another example is:

http://www.anthropologie.com/anthro/product/shopnew-clothes/24832271.jsp

The number portion (Ex: 25423310) is the only part of the URL string that is different which is input by the user in a Userform. It appears that the line of code containing the image is always on line 30 in the HTML code.

Thanks for taking a look into this for me. I appreciate it.
 
Upvote 0
I just get the home page, do I need to be logged in?

There should be no log in. Each of the above URL's should bring up different products based on the # string in the URL.

Unsure why it would not work. However, If you go to the homepage. http://www/anthropologie.com

and click on new arrivals then click any product pictures (dress etc..) it should take you to the same webpage format that I am looking at. It should have a large image of the product on the left hand side of the page with the option to "open in new window" below the picture. It is the product picture that I am trying to copy and paste back into Excel. Since each product ID# is different it takes me to a differnt webpage based on user input. All of the images seem to have this product ID# in the file name but, they also have additional #'s. If you click on the picture and view source code it should be line 30 of the code, regardless of what product you have selected.

Does this help any?
 
Upvote 0
Give this a whirl, it's easier to skip ie altogether
Code:
Sub Anthro()Dim url As String
With CreateObject("MSXML2.XMLHTTP")
    .Open "GET", "http://us.anthropologie.com/anthro/product/shopnew-clothes/" & TextBox1.Value & ".jsp"
    .Send
    Do: DoEvents: Loop Until .readystate = 4
    url = Split(Split(Split(.responsetext, "<noscript>")(1), "' />")(0), "src='")(1)
    .abort
End With


Sheet1.Pictures.Insert (url)


End Sub
 
Upvote 0
Kyle,

This is the code I have used:

Rich (BB code):
Sub Anthro2()
Dim url As String
With CreateObject("MSXML2.XMLHTTP")
    .Open "GET", "http://us.anthropologie.com/anthro/product/shopnew-clothes/" & TextBox1.Value & ".jsp"
    .Send
    Do: DoEvents: Loop Until .readystate = 4
    url = "Split(Split(Split(.responsetext, "
    End With
    End Sub

in conjunction with this:

Rich (BB code):
Private Sub CommandButton1_Click()
Call Anthro2
Unload UserForm1
End Sub

It seems to run the code fine without errors but it did not pull in the image or open a browser. Do I need to use references?
 
Upvote 0
I have used the following code:

Rich (BB code):
Sub Anthro2()
Dim url As String
With CreateObject("MSXML2.XMLHTTP")
    .Open "GET", "http://us.anthropologie.com/anthro/product/shopnew-clothes/" & TextBox1.Value & ".jsp"
    .Send
    Do: DoEvents: Loop Until .readystate = 4
    url = "Split(Split(Split(.responsetext, "
    End With
    End Sub

In conjunction with this code:

Rich (BB code):
Private Sub CommandButton1_Click()
Call Anthro2
Unload UserForm1
End Sub


It seems to run fine but it does not pull the image down.
 
Upvote 0
You can't download an image by parsing HTML.

Parsing the HTML should give you the URL for the image and you should be able to use the DownloadFileFromURL API to actually download the image.
 
Upvote 0

Forum statistics

Threads
1,225,156
Messages
6,183,240
Members
453,152
Latest member
ChrisMd

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