review.controller.js 2.5 KB
Newer Older
1
2
3
4
5
import Review from '../models/Review.js'
import cheerio from "cheerio";
import express from 'express';
import request from 'request-promise'
import jschardet from 'jschardet'
baesangjune's avatar
.    
baesangjune committed
6
// import iconv from 'iconv'
7
import fs from 'fs'
baesangjune's avatar
.    
baesangjune committed
8
9
10
import axios from 'axios';
import { CLIENT_RENEG_LIMIT } from 'tls';
// const Iconv = iconv.Iconv
11
12
13
14
15
16

const signup = async (req, res) => {
    res.send("안녕하세요")
}

const search = async (req, res) => {
baesangjune's avatar
.    
baesangjune committed
17
18
19
20
    // console.log(req.params.search)
    // console.log("req", req)
    // const url = "https://www.google.com/search?q=%ED%95%9C%EB%9D%BC%EC%82%B0%20site%3Atistory.com&oq=tistory&aqs=chrome..69i57j0l4j69i60l3.1746j0j4&sourceid=chrome&ie=UTF-8&ved=2ahUKEwis_bSFz4buAhWVdXAKHU0tBaoQ2wF6BAgIEAE&ei=T1D1X-yZD5XrwQPN2pTQCg"
    const url = "https://www.google.com/search?q=%ED%95%9C%EB%9D%BC%EC%82%B0%20site%3Atistory.com"
21

baesangjune's avatar
.    
baesangjune committed
22
23
24
25
    axios.get(url).then(html => {
        // console.log(response.data)
        fs.writeFile('google.txt', html.data, 'utf8', (err) => console.log(err))
        let $ = cheerio.load(html, null, false);
26
27
28
29
30
31
32
33
34
35
            let places = []
            $('.kCrYT').each(function (i) {
                places[i] = {
                    title: $(this).find('h3').text(),
                    link: $(this).find('a').attr('href'),
                    summary: $(this).find('.s3v9rd ').text(),
                }
            })
            // console.log(places)
            res.send(places)
baesangjune's avatar
.    
baesangjune committed
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
    })
    // request(url)
    //     // .then(anyToUtf8)
    //     .then((html) => {
    //         // fs.writeFileSync("googlez.txt", '\ufeff' + html, { encoding: 'utf8' });

    //         let $ = cheerio.load(html, null, false);
    //         let places = []
    //         $('.kCrYT').each(function (i) {
    //             places[i] = {
    //                 title: $(this).find('h3').text(),
    //                 link: $(this).find('a').attr('href'),
    //                 summary: $(this).find('.s3v9rd ').text(),
    //             }
    //         })
    //         // console.log(places)
    //         res.send(places)
    //     })
    // function anyToUtf8(str) {
    //     const { encoding } = jschardet.detect(str);
    //     console.log("source encoding = " + encoding);
    //     const iconv = new Iconv(encoding, "utf-8//translit//ignore");
    //     return iconv.convert(str).toString();
    // }
60
61
62
63
64
65
66
67
68
69
70
71
72


    // try {
    //     const newPlace = await new Place({
    //         name: req.params.search,
    //         address,
    //         img,

    //     })
    // }
}

export default { signup, search }