JS 모듈 JSP에 적용 질문

조회수 358회

const request = require("request");

const cheerio = require("cheerio");

const iconv = require("iconv-lite");

function setPrintData()
{
  const getNews = () => {
    request(
      {
        url: "http://book.interpark.com/display/collectlist.do?_method=bestsellerHourNew&bookblockname=b_gnb&booklinkname=%BA%A3%BD%BA%C6%AE%C1%B8&bid1=w_bgnb&bid2=LiveRanking&bid3=main&bid4=001",
        method: "GET",
        encoding: null,
      },
      (error, response, body) => {
        if (error) {
          console.error(error);
          return;
        }
        if (response.statusCode === 200) {
          console.log("response ok");
          const bodyDecoded = iconv.decode(body, "euc-kr");
          const $ = cheerio.load(bodyDecoded);

          const img = $(
            ".coverImage > label > a"
          ).toArray();

          const list_text_inner_arr = $(
            ".rankBestContentList > ol > li > div"
          ).toArray();

          const result = [];
          list_text_inner_arr.forEach((div) => {
            const title = $(div).find(".itemName").text().trim();
            const author = $(div).find(".itemMeta .author").text().trim();
            const path = $(div).find("a").first().attr("href");
            // 도메인을 붙인 url 주소
            const url = `http://book.interpark.com/display/collectlist.do?_method=bestsellerHourNew&bookblockname=b_gnb&booklinkname=%BA%A3%BD%BA%C6%AE%C1%B8&bid1=w_bgnb&bid2=LiveRanking&bid3=main&bid4=001${path}`;
            const imgurl = $(div).find("img").first().attr("src");

            result.push({
              url,
              title,
              author,
              imgurl,
            });
          });
          console.log(result);
        }
      });
  };
  getNews();
}

해당 js의 결과를 jsp에 출력하고 싶은데 어떻게 해야할지를 모르겠네요. 많음 도움 부탁드립니다.

답변을 하려면 로그인이 필요합니다.

프로그래머스 커뮤니티는 개발자들을 위한 Q&A 서비스입니다. 로그인해야 답변을 작성하실 수 있습니다.

(ಠ_ಠ)
(ಠ‿ಠ)