웹 페이지에서 콘텐츠를 추출하고 싶습니다. 그러나 응답 텍스트를 받으면 자바 스크립트가 포함되어 브라우저에서 열어 본 페이지처럼 처리 할 수 없습니다.VBA - XMLHTTP GET 요청에서 JavaScript 콘텐츠 다루기
이 방법을 사용하여 HTML 콘텐츠를 가져 오거나 브라우저 에뮬레이션 만 도움이 될 수 있습니까? 아니면이 콘텐츠를 수신하는 몇 가지 다른 방법이 있습니까?
Dim oXMLHTTP As New MSXML2.XMLHTTP
Dim htmlObj As New HTMLDocument
With oXMLHTTP
.Open "GET", "http://www.manta.com/ic/mtqyfk0/ca/riverbend-holdings-inc", False
.send
If .ReadyState = 4 And .Status = 200 Then
htmlObj.body.innerHTML = .responseText
'do things
End If
End With
응답 텍스트 :
<!DOCTYPE html>
<head>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<meta http-equiv="cache-control" content="max-age=0" />
<meta http-equiv="cache-control" content="no-cache" />
<meta http-equiv="expires" content="0" />
<meta http-equiv="expires" content="Tue, 01 Jan 1980 1:00:00 GMT" />
<meta http-equiv="pragma" content="no-cache" />
<meta http-equiv="refresh" content="10; url=/distil_r_blocked.html?Ref=/ic/mtq599v/ca/45th-street-limited-partnership&distil_RID=2115B138-A1BF-11E6-A957-C0595F6B962F&distil_TID=20161103121454" />
<script type="text/javascript">
(function(window){
try {
if (typeof sessionStorage !== 'undefined'){
sessionStorage.setItem('distil_referrer', document.referrer);
}
} catch (e){}
})(window);
</script>
<script type="text/javascript" src="/ser-yrbwqfedrrwwvctvyavy.js" defer></script><style type="text/css">#d__fFH{position:absolute;top:-5000px;left:-5000px}#d__fF{font-family:serif;font-size:200px;visibility:hidden}#verxvaxcuczwcwecuxsx{display:none!important}</style></head>
<body>
<div id="distil_ident_block"> </div>
</body>
</html>
[일반적으로] 서버가 응답을 보내면받는 메시지가 전송됩니다. "HTML 만"을 요청할 수는 없습니다 (서버가 어떤 식 으로든 이것을 지원하도록 구성되어 있지 않은 경우는 거의 없습니다). 동적 인 내용을 다룰 수있는 유일한 방법은 브라우저 자동화/셀레늄/등입니다. –
스크립트를 가져 오는 이유는 HTML 파일에 직접 있기 때문입니다. HTML 파서를 사용하여 컨텐트를 다운로드 한 후 스크립트 태그를 제거 할 수 있습니다. DOM을 구문 분석하는 방법에 대한 다음 스레드를 참조 할 수 있습니다 (http://stackoverflow.com/a/28917205/1640090). – vbguyny