Skip to content

javaScript:웹크롤링 질문입니다! #63

Description

@hyperpace

제가 특정 사이트를 크롤링 하고 싶습니다.
그런데 cros 문제가 있더라구요.. 그래서 검색을 많이해보고 이해하려고 노력했지만
이해가 잘 안되서요.

  1. 도대체 브라우저에서 서버까지 어떤 요청과 응답이 있는건가요?
  2. 요청이나 응답을 받을 때 header값이 있던데 header의 역할은 무엇인가요?
  3. 클라이언트 측에서는 크롤링이 불가능한건가요?
(function() {
  var httpRequest;
  window.onload = function() { makeRequest('http://coinmarketcal.com/'); };
 
  function makeRequest(url) {
    if (window.XMLHttpRequest) { // Mozilla, Safari, ...
      httpRequest = new XMLHttpRequest();
    } else if (window.ActiveXObject) { // IE
      try {
        httpRequest = new ActiveXObject("Msxml2.XMLHTTP");
      } 
      catch (e) {
        try {
          httpRequest = new ActiveXObject("Microsoft.XMLHTTP");
        } 
        catch (e) {}
      }
    }
 
    if (!httpRequest) {
      alert('Giving up :( Cannot create an XMLHTTP instance');
      return false;
    }
    httpRequest.onreadystatechange = alertContents;
    console.log("Hello")

    httpRequest.open('GET', url);
    httpRequest.send();
  }
 
  function alertContents() {
    if (httpRequest.readyState === 4) {
      if (httpRequest.status === 200) {
        alert(httpRequest.responseText);
      } else {
        alert('There was a problem with the request.');
      }
    }
  }
})();

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions