Commit 517cbcbb authored by Kim, Chaerin's avatar Kim, Chaerin
Browse files

불러오고 저장 끝+ 중복확인 필요

parent 750a7171
[{"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\reportWebVitals.js":"1"},{"size":362,"mtime":1608689675665,"results":"2","hashOfConfig":"3"},{"filePath":"4","messages":"5","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1n20xnc","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\reportWebVitals.js",[]] [{"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\reportWebVitals.js":"1","C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\Search.js":"2"},{"size":362,"mtime":1608689675665,"results":"3","hashOfConfig":"4"},{"size":9422,"mtime":1611064279531,"results":"5","hashOfConfig":"4"},{"filePath":"6","messages":"7","errorCount":0,"warningCount":0,"fixableErrorCount":0,"fixableWarningCount":0},"1n20xnc",{"filePath":"8","messages":"9","errorCount":0,"warningCount":3,"fixableErrorCount":0,"fixableWarningCount":0,"source":null},"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\reportWebVitals.js",[],"C:\\Users\\sag06\\Desktop\\project\\search-page\\client\\src\\Pages\\Search.js",["10","11","12"],{"ruleId":"13","severity":1,"message":"14","line":5,"column":83,"nodeType":"15","messageId":"16","endLine":5,"endColumn":93},{"ruleId":"13","severity":1,"message":"17","line":14,"column":12,"nodeType":"15","messageId":"16","endLine":14,"endColumn":18},{"ruleId":"18","severity":1,"message":"19","line":81,"column":35,"nodeType":"20","endLine":81,"endColumn":76},"no-unused-vars","'Pagination' is defined but never used.","Identifier","unusedVar","'mobile' is assigned a value but never used.","react/jsx-no-duplicate-props","No duplicate props allowed","JSXAttribute"]
\ No newline at end of file \ No newline at end of file
...@@ -22,7 +22,7 @@ function Search(props) { ...@@ -22,7 +22,7 @@ function Search(props) {
}, []); }, []);
const places = [{ const places = [{
name: "한라산(hallasan)", name: "한라산",
address: "제주 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W8doAAAAAElFTkSuQmCC",
// img: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg/269px-KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg?size=200x200", // img: "https://upload.wikimedia.org/wikipedia/commons/thumb/e/eb/KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg/269px-KOCIS_Halla_Mountain_in_Jeju-do_%286387785543%29.jpg?size=200x200",
......
import Review from '../models/Review.js'
import cheerio, { html } from "cheerio";
import jschardet from 'jschardet'
import iconv from 'iconv'
import fs from 'fs'
import axios from 'axios';
import { nextTick } from 'process';
const Iconv = iconv.Iconv
const search = async (req, res, next) => {
// const url = "https://www.google.com/search?q=" + encodeURI(req.params.search) + "+site%3Atistory.com&page_no=1"
const url = "https://www.google.com/search?q=" + encodeURI("한라산") + "+site%3Atistory.com&page_no=1"
let reviews = []
try {
axios.get(url)
// .then(anyToUtf8)
.then((html) => {
const $1 = cheerio.load(html.data);
$1('.kCrYT').each(function (i) {
const searchParams = new URLSearchParams($1(this).find('a').attr('href'));
const title = $1(this).find('h3').text()
const link = searchParams.get("/url?q")
const summary = $1(this).find('.s3v9rd').find('.s3v9rd').text()
const response = axios.get(link)
console.log(response)
// const $2 = cheerio.load(toString(response.data));
let content = "없음"
// if ($2('.tt_article_useless_p_margin').text()) {
// content = $2('.tt_article_useless_p_margin').text()
// }
if (title) {
reviews[i] = { title: title, link: link, content: content }
} else if (summary) {
reviews[i - 1] = { ...reviews[i - 1], summary: summary }
reviews = reviews.filter(e => e)
}
// reviews.forEach((review, i) => {
// axios.get(review.link)
// .then((html) => {
// const $2 = cheerio.load(html.data);
// let content = '없음'
// if ($2('.tt_article_useless_p_margin').text()) {
// content = $2('.tt_article_useless_p_margin').text()
// }
// // fs.writeFileSync(`tistory${i}.txt`, '\ufeff' + html.data, { encoding: 'utf8' });
// // console.log(`${i}번째, ${review.content}`)
// review["content"] = content
// // console.log(review)
// })
// })
// // const review = new Review(reviews).save()
})
res.send(reviews)
})
} catch (error) {
console.log(error)
res.status(500).send('리뷰 저장 에러')
}
}
const getReview = (link) => {
let content = '없음'
const res = axios.get(link)
console.log(res)
// const $2 = cheerio.load(res.data);
// if ($2('.tt_article_useless_p_margin').text()) {
// content = $2('.tt_article_useless_p_margin').text()
// }
console.log(content)
return content
}
export default { search, getReview }
\ No newline at end of file
import Review from '../models/Review.js'
import cheerio, { html } from "cheerio";
import jschardet from 'jschardet'
import iconv from 'iconv'
import fs from 'fs'
import axios from 'axios';
import { nextTick } from 'process';
import { response } from 'express';
const Iconv = iconv.Iconv
const search = async (req, res, next) => {
const url = "https://www.google.com/search?q=" + encodeURI(req.params.search) + "+site%3Atistory.com&page_no=1"
let reviews = []
try {
axios.get(url)
.then((response1) => {
const $1 = cheerio.load(response1.data);
$1('.kCrYT').each(function (i) {
const searchParams = new URLSearchParams($1(this).find('a').attr('href'));
const title = $1(this).find('h3').text()
const link = searchParams.get("/url?q")
const summary = $1(this).find('.s3v9rd').find('.s3v9rd').text()
if (title) {
reviews[i] = { title: title, link: link, }
} else if (summary) {
reviews[i - 1] = { ...reviews[i - 1], summary: summary }
reviews = reviews.filter(e => e)
}
// const review = new Review(reviews).save()
})
res.send(reviews)
})
} catch (error) {
// reviews.forEach((review) => {
// axios.get(review.link)
// .then((response2) => {
// const $2 = cheerio.load(response2.data);
// let content = ''
// if ($2('.tt_article_useless_p_margin').text()) {
// content = $2('.tt_article_useless_p_margin').text()
// }
// review = { content: content }
// console.log("dkssud")
// })
// console.log("dkssud")
// })
// console.log(content)
res.status(500).send(error)
}
}
const getReview = async (link) => {
let content = '없음'
const res = await axios.get(link)
const $2 = cheerio.load(res.data);
if ($2('.tt_article_useless_p_margin').text()) {
content = $2('.tt_article_useless_p_margin').text()
}
console.log(content, "getReiview")
return content
}
export default { search, getReview }
\ No newline at end of file
...@@ -28,8 +28,9 @@ const search = async (req, res, next) => { ...@@ -28,8 +28,9 @@ const search = async (req, res, next) => {
reviews = reviews.filter(e => e) reviews = reviews.filter(e => e)
} }
}) })
const promiseReview = await Promise.all(content) let promiseReview = await Promise.all(content)
reviews.forEach(async(review, i) => { promiseReview = promiseReview.filter(e => typeof (e) === 'string')
reviews.forEach(async (review, i) => {
review["content"] = promiseReview[i] review["content"] = promiseReview[i]
}) })
res.send(reviews) res.send(reviews)
...@@ -40,15 +41,16 @@ const search = async (req, res, next) => { ...@@ -40,15 +41,16 @@ const search = async (req, res, next) => {
} }
const getReview = async (link) => { const getReview = async (link) => {
let content = '없음'
if (link) { if (link) {
let content = '없음'
const res = await axios.get(link) const res = await axios.get(link)
const $2 = cheerio.load(res.data); const $2 = cheerio.load(res.data);
if ($2('.tt_article_useless_p_margin').text()) { if ($2('.tt_article_useless_p_margin').text()) {
content = $2('.tt_article_useless_p_margin').text() content = $2('.tt_article_useless_p_margin').text()
} }
}
return content return content
console.log(content, link)
}
} }
export default { search, getReview } export default { search, getReview }
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment