Commit 6dc328f1 authored by Lee SeoYeon's avatar Lee SeoYeon
Browse files

Merge remote-tracking branch 'origin/cherry' into lsy

parents 90d3d8ee b62079ad
......@@ -9,7 +9,9 @@ function Place(props) {
axios({ url: `/api/review?keyword=${props.place.name}`, method: 'post', data: { db: db } })
.then(res => {
console.log("place res.data", res.data)
setReviews(res.data)
setReviews(res.data.review)
setDb(res.data.db)
console.log(db)
})
.catch(err => {
console.log(err)
......
......@@ -14,7 +14,7 @@ function Search(props) {
const [index, setIndex] = useState(1);
const [showSet, setShowSet] = useState([false, false, false, false]);
const [search, setSearch] = useState(queryString.parse(props.location.search).keyword);
const [mobile, setMobile] = useState();
const [pagePlace, setPagePlace] = useState();
const [association, setAssociation] = useState([])
const [pagePlace, setPagePlace] = useState([])
const [bookmark, setBookmark] = useState([false, false, false, false])
......@@ -42,8 +42,6 @@ function Search(props) {
// })
// }
const getAssociation = () => {
axios.get(`/api/search/association?keyword=${search}`)
.then(res => {
......@@ -59,27 +57,38 @@ function Search(props) {
useEffect(() => {
getAssociation()
if (window.innerWidth < 960) {
setMobile(true)
} else {
setMobile(false)
}
}, []);
useEffect(() => {
setPagePlace(paginate(association, index, association.length))
}, [association])
}, [association]);
useEffect(() => {
getAssociation()
if (state) {
// window.location.reload()
// return <Redirect to={{
// pathname: `/search?keyword=${search}`,
// state: { id: search },
// }} />;
props.history.push('/search?keyword=' + search)
setState(false)
console.log("search야", search)
}
// setState(false)
// console.log("search야", search)
} window.addEventListener("scroll", infiniteScroll);
return () => { window.removeEventListener("scroll", infiniteScroll); }
}, []);
}, [state])
const infiniteScroll = () => {
const { documentElement, body } = document;
const scrollHeight = Math.max(documentElement.scrollHeight, body.scrollHeight);
const scrollTop = Math.max(documentElement.scrollTop, body.scrollTop);
const clientHeight = documentElement.clientHeight;
if (scrollTop + clientHeight >= scrollHeight) {
// getReview();
console.log("더불러")
}
console.log(scrollHeight, scrollTop, clientHeight)
}
const places = [{
......
This diff is collapsed.
This diff is collapsed.
......@@ -15,44 +15,32 @@ const searchPlace = async (req, res, next,) => {
console.log("2222222222222222222222222222222222222222222222222222222")
const url = "https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=" + encodeURI(req.query.keyword)
const editUrl = /(http(s)?:\/\/)([a-z0-9\w]+\.*)+[a-z0-9]{2,4}/gi
axios.get(url)
.then(async (response) => {
const html = response.data
// fs.writeFileSync("googleReview", html, { encoding: 'utf-8' })
const { data: html } = await axios.get(url)
let $1 = cheerio.load(html);
let places = {}
$1('.ct_box_area').each(function (i) {
places={
name: $1('.biz_name').text(), category: $1('.category').text(), address: $1('.addr').text()
places = {
name: $1('.biz_name').text(), category: $1('.category').text(), address: $1('.addr').text(),
img: "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd",
times: []
}
})
// 값이 비어있거나 에러가 생겼을 때를 대비해 try catch를 해야함
// const newPlaces = await new Places(places[0]
// ).save()
// res.send(places)
req.places = places[0]
console.log("62168748172", req.places)
})
req.places = places
}
next()
}
const searchImg = async (req, res, next) => {
console.log("d213532513212osfnlagm2214124", req.places)
if (req.places.img) {
if (req.places.img !== "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd") {
console.log("333333333333333333333333333IMG@@@@@@@@@@@@@@@@@@@ 기존이미지줄력중")
req.places.times.push(new Date().toLocaleString())
console.log("세이브 전 111111111111111111", req.places)
const newPlaces = await new Places(req.places).save()
next()
} else {
} else if (req.places.img === "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd") {
const imgUrl = "https://www.google.com/search?q=" + encodeURI(req.query.keyword) + "+site:tistory.com/&sxsrf=ALeKk023Dv08KQDodRmpB5222lQuzw2Vaw:1610612821100&source=lnms&tbm=isch"
axios.get(imgUrl)
......@@ -61,10 +49,9 @@ const searchImg = async (req, res, next) => {
const html = response.data
let name = req.query.keyword
let $1 = cheerio.load(html);
let images = $1('.RAyV4b').find('img').attr('src')
req.places.img = images
console.log("4141414141414141", req.places)
//사진만 업데이트
// let Place2 = await Places.findOne({ name: req.query.keyword })
req.places.times.push(new Date().toLocaleString())
......@@ -73,10 +60,10 @@ const searchImg = async (req, res, next) => {
console.log("세이브 전 222222222222222", req.places)
const newPlaces = await new Places(req.places).save()
next()
})
} else {
console.log("이미지 생성 오류발생!!")
}
}
// if (DuplicateCheckImg !== "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd") {
......@@ -122,16 +109,15 @@ const searchAssociation = async (req, res) => {
// }
if (!Place3) {
console.log("asdfasdfasdf222222222222222222dsaf2222222222214123q5", Place3)
res.send({ error: "Place.address is null" })
}
else {
let addresse = Place3.split(' ')[0]
let AssociationsId = []
let addressPlaces = new RegExp(`${addresse}`)
let responsePlaces = await Places.find({ address: addressPlaces })
// const newPlaces = await new Places(places[0]).save()
let responsePlaces = await Places.find({ address: addressPlaces }).sort({ updatedAt: -1 })
//몽구스나 몽고디비에 있는 sort 확인해보고 나열하기.
console.log("$$$$$$$$$$$4", responsePlaces)
res.send(responsePlaces)
}
// responsePlaces.map(Association => {
......
......@@ -3,98 +3,71 @@ import cheerio from "cheerio";
import axios from 'axios';
const search = async (req, res, next) => {
console.log("1")
for (let i = 1; (req.reviews).length > 10; i++) {
console.log(req.reviews, "1")
try {
console.log("2")
for (let j = 1; j < 2; j++) {
let reviews = []
let content = []
const url = "https://www.google.com/search?q=" + encodeURI(req.query.keyword) + "+site%3Atistory.com&page_no=" + i
const response1 = await axios.get(url)
// console.log(response1.data)
const $1 = cheerio.load(response1.data);
// console.log(req.reviews, "제발")/
let url = "https://www.google.com/search?q=" + encodeURI(req.query.keyword) + "+site%3Atistory.com&page_no=" + j
let response1 = await axios.get(url)
let $1 = cheerio.load(response1.data);
$1('.kCrYT').each(async function (i) {
console.log("3")
const title = $1(this).find('h3').text()
const searchParams = new URLSearchParams($1(this).find('a').attr('href'));
const link = searchParams.get("/url?q")
const summary = $1(this).find('.s3v9rd').find('.s3v9rd').text()
Review.find({ link: link }, function (err, review) {
if (!review) {
content.push(getReview(link))
let title = $1(this).find('h3').text()
let searchParams = new URLSearchParams($1(this).find('a').attr('href'));
let link = searchParams.get("/url?q")
let 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)
}
}
})
})
let promiseReview = await Promise.all(content)
promiseReview = promiseReview.filter(e => typeof (e) === 'string')
reviews.forEach(async (review, i) => {
reviews.forEach((review, i) => {
Review.findOne({ link: review.link }, async function (err, reviewss) {
console.log("4")
review["content"] = promiseReview[i]
const reviews = new Review(review).save()
reviews.keyword.push(req.query.keyword)
req.reviews.push(reviews)
if (err) { return res.status(404).send({ error: err }) }
if (reviewss) {
reviewss.keyword = [...reviewss.keyword, req.query.keyword]
reviewss.save()
}
if (!reviewss) {
reviews["keyword"] = [req.query.keyword]
let Reviews = await new Review(review).save()
// console.log(Reviews,"1")
req.reviews.push(Reviews)
}
})
console.log("5")
res.send(reviews)
})
}
const a = await Promise.all(req.reviews)
console.log(a, "2")
res.status(200).send({ review: a, db: true })
} catch (error) {
console.log("6")
console.log(error)
res.send(error)
}
}
}
//***************네이버 크롤링 할 때 ********************* */
// try {
// let reviews = []
// let content = []
// const url = "https://search.naver.com/search.naver?where=view&sm=tab_jum&query=" + encodeURI('한라산')
// const response1 = await axios.get(url)
// // console.log(response1.data)
// const $1 = cheerio.load(response1.data);
// $1('._list').find('.total_wrap').each(async function (i) {
// reviews[i] = { name: $1(this).find('.total_tit').text(), summery: $1(this).find('.dsc_txt').text(), link: $1(this).find('.total_tit').attr('href') }
// })
// res.send(reviews)
// } catch (error) {
// console.log(error)
// res.send(error)
// }
// }
const getReview = async (link) => {
let content = '없음'
if (link) {
const res = await axios.get(link)
const $2 = cheerio.load(res.data); // cheerio 의미
if ($2('.tt_article_useless_p_margin').text()) {
content = $2('.tt_article_useless_p_margin').text()
const find = (req, res, next) => {
console.log("7", req.query.keyword)
const keyword = req.query.keyword
if (req.body.db) {
next()
}
Review.find({ keyword: keyword }, function (err, reviews) {
req.reviews = []
if (reviews) {
if (reviews.length > 10) {
res.status(200).send({ review: reviews, db: true })
}
return content
}
const find = (req, res, next) => {
res.send("안녕")
// console.log("7", req.body)
// if (req.body.db) {
// next()
// }
// Review.find({ keyword:{ $elemMatch: res.query.keyword } }, function (err, reviews) {
// if (reviews) {
// if (reviews.length > 10)
// res.send(reviews, { db: true })
// req.reviews = reviews
// }
// next()
// })
req.reviews = reviews
}
next()
})
}
export default { search, find }
......@@ -15,9 +15,6 @@ const ReviewSchema = new mongoose.Schema({
type: String,
// required: true,
},
content: {
type: String,
},
keyword: {
type: Array,
// required: true,
......
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