import Place from '../models/Place.js' import cheerio from 'cheerio' import fs from 'fs' import axios from 'axios'; const searchPlace = async (req, res) => { console.log("여기까지는 옵니다~") const url = "https://www.google.com/search?q=" + encodeURI(req.params.search) + "+site%3Atistory.com&page_no=1" const editUrl = /(http(s)?:\/\/)([a-z0-9\w]+\.*)+[a-z0-9]{2,4}/gi axios.get(url) .then((response) => { const html = response.data let $1 = cheerio.load(html); let places = [] $1('.kCrYT').each(function (i) { if ($1(this).find('h3').text()) { places[i] = { name: $1(this).find('h3').text(), link: ($1(this).find('a').attr('href')) } } else if ($1(this).find('.s3v9rd').find('.s3v9rd').text()) { places[i - 1] = { ...places[i - 1], address: $1(this).find('.s3v9rd').find('.s3v9rd').text() } places = places.filter(e => e) } }) console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", places) res.send(places) }) } const searchImg = async (req, res) => { const imgUrl = "https://www.google.com/search?q=" + encodeURI(req.params.search) + "+site:tistory.com/&sxsrf=ALeKk023Dv08KQDodRmpB5222lQuzw2Vaw:1610612821100&source=lnms&tbm=isch" axios.get(imgUrl) .then((response) => { const html = response.data let $1 = cheerio.load(html); let images = $1('.RAyV4b').find('img').attr('src') // let images = [] // $1('.RAyV4b').each(function (i) { // images[i] = { imgUrl: $(this).find('img').atrr('src') } // }) // console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%', images) res.send(images) }) } export default { searchImg, searchPlace }