VBA, MSXML2.XMLHTTP60 parse in head section -
i use webpage
dim xhr msxml2.xmlhttp60 set xhr = new msxml2.xmlhttp60 on error resume next xhr .open "get", url, false .send if .readystate = 4 , .status = 200 set doc = new mshtml.htmldocument doc.body.innerhtml = .responsetext htmlrequesthttp = true else msgbox "internet error, please check:" & vbnewline & "ready state: " & .readystate & _ vbnewline & "http request status: " & .status htmlrequesthttp = false end if end
but doc.getelementsbytagname("meta") misses tags head section. .response complete (i checked) how can access head elemnts? thanks,
don't write document body. write document itself.
set doc = new mshtml.htmldocument doc.write httpget(url) msgbox doc.getelementsbytagname("meta").length function httpget(url) new msxml2.xmlhttp60 .open "get", url, false on error resume next .send if .status = 200 httpget = .responsetext else msgbox "http request status: " & .status, , "httpget error" end if on error goto 0 end end function
as general tip, don't use on error resume next
except next statement.
ideally, wrap statements can fail in dedicated function keep areas of code covered on error resume next
absolute minimum, did.
Comments
Post a Comment