ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Getting data from a webpage (https://www.excelbanter.com/excel-programming/438540-getting-data-webpage.html)

Southern at Heart

Getting data from a webpage
 
Okay, I'm needing to do this same thing again, but can't figure out where the
item/innertext I need is:
The webpage is:
http://www.gocomics.com/calvinandhobbes/2010/01/16

....and what I need is the image (on this particular page it's):
http://imgsrv.gocomics.com/dim/?fh=8...8010a8&w=900.0

thanks, SouthernAtHeart


"Joel" wrote:

You don't need to get the source. You can use the IE explorer like below to
help you filter the data. The source is under the IE.Document.all property.
You can get these lines by doing a loop like this

for each itm in IE.Document
'your code here
next itm

You can use the methods getElementsByTagname(), and getElementById() to help
you filter the data. I often for debuggin use something like this

RowCount = 1
for each itm in IE.Document
Range("A" & RowCount) = itm.tagname
Range("B" & RowCount) = itm.Classname
Range("C" & RowCount) = itm.id
Range("D" & RowCount) = left(itm.innertext,1024)

RowCount = rowcount + 1
next itm

The source is partioned into items. Has you go down the ALL property the
innertext is partioned into small pices. When you do the dump above you will
see the same innertext repeated over and over again but broken into samller
pieces each time it is repeated.

If you need more help give me the URL and I will get what you need. I help
lots of people who have had problems.


ron

Getting data from a webpage
 
On Jan 18, 12:14*pm, Southern at Heart
wrote:
Okay, I'm needing to do this same thing again, but can't figure out where the
item/innertext I need is:
The webpage is:http://www.gocomics.com/calvinandhobbes/2010/01/16

...and what I need is the image (on this particular page it's):http://imgsrv.gocomics.com/dim/?fh=8...078a548010a8&w...

thanks, SouthernAtHeart


The following should do want you want. It will paste the image to the
activesheet, but once it is in the clipboard you can do whatever you
want with it...Ron

Sub Comics()
' Open the first webpage
Set ie = CreateObject("InternetExplorer.Application")

With ie
.Visible = True
.navigate "http://www.gocomics.com/calvinandhobbes/2010/01/16
"
.Top = 50
.Left = 530
.Height = 400
.Width = 400

' Loop until the page is fully loaded
Do Until .ReadyState = 4 And Not .Busy
DoEvents
Loop

' Determine the url for the image
my_var = ie.document.body.innerhtml
loc_1 = InStr(1, my_var, "feature_item", vbTextCompare)
loc_2 = InStr(loc_1, my_var, "//", vbTextCompare)
loc_3 = InStr(3 + loc_2, my_var, "", vbTextCompare)
my_url = Trim(Mid(my_var, 2 + loc_2, loc_3 - (2 + loc_2)))

' Go to the image url and copy the image and paste to the activesheet
ie.navigate my_url

Do Until ie.ReadyState = 4 And Not ie.Busy
DoEvents
Loop

ie.ExecWB 17, 2
ie.ExecWB 12, 0
ActiveSheet.PasteSpecial

End With

ie.Quit
End Sub

Southern at Heart

Getting data from a webpage
 
Thanks.
Works great!
What would I need to change to make this work in Word 2003?
Seems like it all works accept the activesheet.pastespecial.
I thought it might be activedocument.pastespecial, but it must not be...
thanks again.

Southern at Heart

One step further
 
How can I end this code so that it will save the image in 'My Documents'
instead of pasting it into the word document? It is a .gif format on the
web, but it can be something else if it's easier.
Thanks.

"ron" wrote:

On Jan 18, 12:14 pm, Southern at Heart
wrote:
Okay, I'm needing to do this same thing again, but can't figure out where the
item/innertext I need is:
The webpage is:http://www.gocomics.com/calvinandhobbes/2010/01/16

...and what I need is the image (on this particular page it's):http://imgsrv.gocomics.com/dim/?fh=8...078a548010a8&w...

thanks, SouthernAtHeart


The following should do want you want. It will paste the image to the
activesheet, but once it is in the clipboard you can do whatever you
want with it...Ron

Sub Comics()
' Open the first webpage
Set ie = CreateObject("InternetExplorer.Application")

With ie
.Visible = True
.navigate "http://www.gocomics.com/calvinandhobbes/2010/01/16
"
.Top = 50
.Left = 530
.Height = 400
.Width = 400

' Loop until the page is fully loaded
Do Until .ReadyState = 4 And Not .Busy
DoEvents
Loop

' Determine the url for the image
my_var = ie.document.body.innerhtml
loc_1 = InStr(1, my_var, "feature_item", vbTextCompare)
loc_2 = InStr(loc_1, my_var, "//", vbTextCompare)
loc_3 = InStr(3 + loc_2, my_var, "", vbTextCompare)
my_url = Trim(Mid(my_var, 2 + loc_2, loc_3 - (2 + loc_2)))

' Go to the image url and copy the image and paste to the activesheet
ie.navigate my_url

Do Until ie.ReadyState = 4 And Not ie.Busy
DoEvents
Loop

ie.ExecWB 17, 2
ie.ExecWB 12, 0
ActiveSheet.PasteSpecial

End With

ie.Quit
End Sub
.



All times are GMT +1. The time now is 01:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com