Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
students
search-page
Commits
6dc328f1
Commit
6dc328f1
authored
Jan 27, 2021
by
Lee SeoYeon
Browse files
Merge remote-tracking branch 'origin/cherry' into lsy
parents
90d3d8ee
b62079ad
Changes
7
Expand all
Hide whitespace changes
Inline
Side-by-side
client/src/Components/Place.js
View file @
6dc328f1
...
@@ -9,7 +9,9 @@ function Place(props) {
...
@@ -9,7 +9,9 @@ function Place(props) {
axios
({
url
:
`/api/review?keyword=
${
props
.
place
.
name
}
`
,
method
:
'
post
'
,
data
:
{
db
:
db
}
})
axios
({
url
:
`/api/review?keyword=
${
props
.
place
.
name
}
`
,
method
:
'
post
'
,
data
:
{
db
:
db
}
})
.
then
(
res
=>
{
.
then
(
res
=>
{
console
.
log
(
"
place res.data
"
,
res
.
data
)
console
.
log
(
"
place res.data
"
,
res
.
data
)
setReviews
(
res
.
data
)
setReviews
(
res
.
data
.
review
)
setDb
(
res
.
data
.
db
)
console
.
log
(
db
)
})
})
.
catch
(
err
=>
{
.
catch
(
err
=>
{
console
.
log
(
err
)
console
.
log
(
err
)
...
...
client/src/Pages/Search.js
View file @
6dc328f1
...
@@ -14,7 +14,7 @@ function Search(props) {
...
@@ -14,7 +14,7 @@ function Search(props) {
const
[
index
,
setIndex
]
=
useState
(
1
);
const
[
index
,
setIndex
]
=
useState
(
1
);
const
[
showSet
,
setShowSet
]
=
useState
([
false
,
false
,
false
,
false
]);
const
[
showSet
,
setShowSet
]
=
useState
([
false
,
false
,
false
,
false
]);
const
[
search
,
setSearch
]
=
useState
(
queryString
.
parse
(
props
.
location
.
search
).
keyword
);
const
[
search
,
setSearch
]
=
useState
(
queryString
.
parse
(
props
.
location
.
search
).
keyword
);
const
[
mobile
,
setMobil
e
]
=
useState
();
const
[
pagePlace
,
setPagePlac
e
]
=
useState
();
const
[
association
,
setAssociation
]
=
useState
([])
const
[
association
,
setAssociation
]
=
useState
([])
const
[
pagePlace
,
setPagePlace
]
=
useState
([])
const
[
pagePlace
,
setPagePlace
]
=
useState
([])
const
[
bookmark
,
setBookmark
]
=
useState
([
false
,
false
,
false
,
false
])
const
[
bookmark
,
setBookmark
]
=
useState
([
false
,
false
,
false
,
false
])
...
@@ -42,8 +42,6 @@ function Search(props) {
...
@@ -42,8 +42,6 @@ function Search(props) {
// })
// })
// }
// }
const
getAssociation
=
()
=>
{
const
getAssociation
=
()
=>
{
axios
.
get
(
`/api/search/association?keyword=
${
search
}
`
)
axios
.
get
(
`/api/search/association?keyword=
${
search
}
`
)
.
then
(
res
=>
{
.
then
(
res
=>
{
...
@@ -59,27 +57,38 @@ function Search(props) {
...
@@ -59,27 +57,38 @@ function Search(props) {
useEffect
(()
=>
{
useEffect
(()
=>
{
getAssociation
()
getAssociation
()
if
(
window
.
innerWidth
<
960
)
{
setMobile
(
true
)
}
else
{
setMobile
(
false
)
}
},
[]);
},
[]);
useEffect
(()
=>
{
useEffect
(()
=>
{
setPagePlace
(
paginate
(
association
,
index
,
association
.
length
))
setPagePlace
(
paginate
(
association
,
index
,
association
.
length
))
},
[
association
])
},
[
association
])
;
useEffect
(()
=>
{
useEffect
(()
=>
{
getAssociation
()
getAssociation
()
if
(
state
)
{
if
(
state
)
{
// window.location.reload()
// return <Redirect to={{
// pathname: `/search?keyword=${search}`,
// state: { id: search },
// }} />;
props
.
history
.
push
(
'
/search?keyword=
'
+
search
)
props
.
history
.
push
(
'
/search?keyword=
'
+
search
)
setState
(
false
)
// setState(false)
console
.
log
(
"
search야
"
,
search
)
// 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
=
[{
const
places
=
[{
...
...
googleReview
deleted
100644 → 0
View file @
90d3d8ee
This diff is collapsed.
Click to expand it.
googleSearch
deleted
100644 → 0
View file @
90d3d8ee
This diff is collapsed.
Click to expand it.
server/controllers/place.controller.js
View file @
6dc328f1
...
@@ -15,44 +15,32 @@ const searchPlace = async (req, res, next,) => {
...
@@ -15,44 +15,32 @@ const searchPlace = async (req, res, next,) => {
console
.
log
(
"
2222222222222222222222222222222222222222222222222222222
"
)
console
.
log
(
"
2222222222222222222222222222222222222222222222222222222
"
)
const
url
=
"
https://search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=
"
+
encodeURI
(
req
.
query
.
keyword
)
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
const
editUrl
=
/
(
http
(
s
)?
:
\/\/)([
a-z0-9
\w]
+
\.
*
)
+
[
a-z0-9
]{2,4}
/gi
axios
.
get
(
url
)
const
{
data
:
html
}
=
await
axios
.
get
(
url
)
.
then
(
async
(
response
)
=>
{
let
$1
=
cheerio
.
load
(
html
);
const
html
=
response
.
data
let
places
=
{}
// fs.writeFileSync("googleReview", html, { encoding: 'utf-8' })
$1
(
'
.ct_box_area
'
).
each
(
function
(
i
)
{
let
$1
=
cheerio
.
load
(
html
);
places
=
{
name
:
$1
(
'
.biz_name
'
).
text
(),
category
:
$1
(
'
.category
'
).
text
(),
address
:
$1
(
'
.addr
'
).
text
(),
let
places
=
{}
img
:
"
https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd
"
,
$1
(
'
.ct_box_area
'
).
each
(
function
(
i
)
{
times
:
[]
places
=
{
}
name
:
$1
(
'
.biz_name
'
).
text
(),
category
:
$1
(
'
.category
'
).
text
(),
address
:
$1
(
'
.addr
'
).
text
()
})
}
req
.
places
=
places
})
// 값이 비어있거나 에러가 생겼을 때를 대비해 try catch를 해야함
// const newPlaces = await new Places(places[0]
// ).save()
// res.send(places)
req
.
places
=
places
[
0
]
console
.
log
(
"
62168748172
"
,
req
.
places
)
})
}
}
next
()
next
()
}
}
const
searchImg
=
async
(
req
,
res
,
next
)
=>
{
const
searchImg
=
async
(
req
,
res
,
next
)
=>
{
console
.
log
(
"
d213532513212osfnlagm2214124
"
,
req
.
places
)
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@@@@@@@@@@@@@@@@@@@ 기존이미지줄력중
"
)
console
.
log
(
"
333333333333333333333333333IMG@@@@@@@@@@@@@@@@@@@ 기존이미지줄력중
"
)
req
.
places
.
times
.
push
(
new
Date
().
toLocaleString
())
req
.
places
.
times
.
push
(
new
Date
().
toLocaleString
())
console
.
log
(
"
세이브 전 111111111111111111
"
,
req
.
places
)
console
.
log
(
"
세이브 전 111111111111111111
"
,
req
.
places
)
const
newPlaces
=
await
new
Places
(
req
.
places
).
save
()
const
newPlaces
=
await
new
Places
(
req
.
places
).
save
()
next
()
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
"
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
)
axios
.
get
(
imgUrl
)
...
@@ -61,10 +49,9 @@ const searchImg = async (req, res, next) => {
...
@@ -61,10 +49,9 @@ const searchImg = async (req, res, next) => {
const
html
=
response
.
data
const
html
=
response
.
data
let
name
=
req
.
query
.
keyword
let
name
=
req
.
query
.
keyword
let
$1
=
cheerio
.
load
(
html
);
let
$1
=
cheerio
.
load
(
html
);
let
images
=
$1
(
'
.RAyV4b
'
).
find
(
'
img
'
).
attr
(
'
src
'
)
let
images
=
$1
(
'
.RAyV4b
'
).
find
(
'
img
'
).
attr
(
'
src
'
)
req
.
places
.
img
=
images
req
.
places
.
img
=
images
console
.
log
(
"
4141414141414141
"
,
req
.
places
)
//사진만 업데이트
//사진만 업데이트
// let Place2 = await Places.findOne({ name: req.query.keyword })
// let Place2 = await Places.findOne({ name: req.query.keyword })
req
.
places
.
times
.
push
(
new
Date
().
toLocaleString
())
req
.
places
.
times
.
push
(
new
Date
().
toLocaleString
())
...
@@ -73,10 +60,10 @@ const searchImg = async (req, res, next) => {
...
@@ -73,10 +60,10 @@ const searchImg = async (req, res, next) => {
console
.
log
(
"
세이브 전 222222222222222
"
,
req
.
places
)
console
.
log
(
"
세이브 전 222222222222222
"
,
req
.
places
)
const
newPlaces
=
await
new
Places
(
req
.
places
).
save
()
const
newPlaces
=
await
new
Places
(
req
.
places
).
save
()
next
()
next
()
})
})
}
else
{
console
.
log
(
"
이미지 생성 오류발생!!
"
)
}
}
}
}
// if (DuplicateCheckImg !== "https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd") {
// 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) => {
...
@@ -122,16 +109,15 @@ const searchAssociation = async (req, res) => {
// }
// }
if
(
!
Place3
)
{
if
(
!
Place3
)
{
console
.
log
(
"
asdfasdfasdf222222222222222222dsaf2222222222214123q5
"
,
Place3
)
console
.
log
(
"
asdfasdfasdf222222222222222222dsaf2222222222214123q5
"
,
Place3
)
res
.
send
({
error
:
"
Place.address is null
"
})
res
.
send
({
error
:
"
Place.address is null
"
})
}
}
else
{
else
{
let
addresse
=
Place3
.
split
(
'
'
)[
0
]
let
addresse
=
Place3
.
split
(
'
'
)[
0
]
let
AssociationsId
=
[]
let
AssociationsId
=
[]
let
addressPlaces
=
new
RegExp
(
`
${
addresse
}
`
)
let
addressPlaces
=
new
RegExp
(
`
${
addresse
}
`
)
let
responsePlaces
=
await
Places
.
find
({
address
:
addressPlaces
})
let
responsePlaces
=
await
Places
.
find
({
address
:
addressPlaces
}).
sort
({
updatedAt
:
-
1
})
// const newPlaces = await new Places(places[0]).save()
//몽구스나 몽고디비에 있는 sort 확인해보고 나열하기.
console
.
log
(
"
$$$$$$$$$$$4
"
,
responsePlaces
)
res
.
send
(
responsePlaces
)
res
.
send
(
responsePlaces
)
}
}
// responsePlaces.map(Association => {
// responsePlaces.map(Association => {
...
...
server/controllers/review.controller.js
View file @
6dc328f1
...
@@ -3,98 +3,71 @@ import cheerio from "cheerio";
...
@@ -3,98 +3,71 @@ import cheerio from "cheerio";
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
const
search
=
async
(
req
,
res
,
next
)
=>
{
const
search
=
async
(
req
,
res
,
next
)
=>
{
console
.
log
(
"
1
"
)
console
.
log
(
req
.
reviews
,
"
1
"
)
for
(
let
i
=
1
;
(
req
.
reviews
).
length
>
10
;
i
++
)
{
try
{
try
{
for
(
let
j
=
1
;
j
<
2
;
j
++
)
{
console
.
log
(
"
2
"
)
let
reviews
=
[]
let
reviews
=
[]
let
content
=
[]
// console.log(req.reviews, "제발")/
const
url
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
query
.
keyword
)
+
"
+site%3Atistory.com&page_no=
"
+
i
let
url
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
query
.
keyword
)
+
"
+site%3Atistory.com&page_no=
"
+
j
const
response1
=
await
axios
.
get
(
url
)
let
response1
=
await
axios
.
get
(
url
)
// console.log(response1.data)
let
$1
=
cheerio
.
load
(
response1
.
data
);
const
$1
=
cheerio
.
load
(
response1
.
data
);
$1
(
'
.kCrYT
'
).
each
(
async
function
(
i
)
{
$1
(
'
.kCrYT
'
).
each
(
async
function
(
i
)
{
console
.
log
(
"
3
"
)
console
.
log
(
"
3
"
)
const
title
=
$1
(
this
).
find
(
'
h3
'
).
text
()
let
title
=
$1
(
this
).
find
(
'
h3
'
).
text
()
const
searchParams
=
new
URLSearchParams
(
$1
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
));
let
searchParams
=
new
URLSearchParams
(
$1
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
));
const
link
=
searchParams
.
get
(
"
/url?q
"
)
let
link
=
searchParams
.
get
(
"
/url?q
"
)
const
summary
=
$1
(
this
).
find
(
'
.s3v9rd
'
).
find
(
'
.s3v9rd
'
).
text
()
let
summary
=
$1
(
this
).
find
(
'
.s3v9rd
'
).
find
(
'
.s3v9rd
'
).
text
()
Review
.
find
({
link
:
link
},
function
(
err
,
review
)
{
if
(
title
)
{
if
(
!
review
)
{
reviews
[
i
]
=
{
title
:
title
,
link
:
link
}
content
.
push
(
getReview
(
link
))
}
else
if
(
summary
)
{
if
(
title
)
{
reviews
[
i
-
1
]
=
{
...
reviews
[
i
-
1
],
summary
:
summary
}
reviews
[
i
]
=
{
title
:
title
,
link
:
link
}
reviews
=
reviews
.
filter
(
e
=>
e
)
}
else
if
(
summary
)
{
}
reviews
[
i
-
1
]
=
{
...
reviews
[
i
-
1
],
summary
:
summary
}
})
reviews
=
reviews
.
filter
(
e
=>
e
)
reviews
.
forEach
((
review
,
i
)
=>
{
}
Review
.
findOne
({
link
:
review
.
link
},
async
function
(
err
,
reviewss
)
{
console
.
log
(
"
4
"
)
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
)
}
}
})
})
})
})
let
promiseReview
=
await
Promise
.
all
(
content
)
promiseReview
=
promiseReview
.
filter
(
e
=>
typeof
(
e
)
===
'
string
'
)
reviews
.
forEach
(
async
(
review
,
i
)
=>
{
console
.
log
(
"
4
"
)
review
[
"
content
"
]
=
promiseReview
[
i
]
const
reviews
=
new
Review
(
review
).
save
()
reviews
.
keyword
.
push
(
req
.
query
.
keyword
)
req
.
reviews
.
push
(
reviews
)
})
console
.
log
(
"
5
"
)
res
.
send
(
reviews
)
}
catch
(
error
)
{
console
.
log
(
"
6
"
)
console
.
log
(
error
)
res
.
send
(
error
)
}
}
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
)
}
}
}
}
//***************네이버 크롤링 할 때 ********************* */
// 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
()
}
}
return
content
}
const
find
=
(
req
,
res
,
next
)
=>
{
const
find
=
(
req
,
res
,
next
)
=>
{
res
.
send
(
"
안녕
"
)
console
.
log
(
"
7
"
,
req
.
query
.
keyword
)
// console.log("7", req.body)
const
keyword
=
req
.
query
.
keyword
// if (req.body.db) {
if
(
req
.
body
.
db
)
{
// next()
next
()
// }
}
// Review.find({ keyword:{ $elemMatch: res.query.keyword } }, function (err, reviews) {
Review
.
find
({
keyword
:
keyword
},
function
(
err
,
reviews
)
{
// if (reviews) {
req
.
reviews
=
[]
// if (reviews.length > 10)
if
(
reviews
)
{
// res.send(reviews, { db: true })
if
(
reviews
.
length
>
10
)
{
// req.reviews = reviews
res
.
status
(
200
).
send
({
review
:
reviews
,
db
:
true
})
// }
}
// next()
req
.
reviews
=
reviews
// })
}
next
()
})
}
}
export
default
{
search
,
find
}
export
default
{
search
,
find
}
server/models/Review.js
View file @
6dc328f1
...
@@ -15,9 +15,6 @@ const ReviewSchema = new mongoose.Schema({
...
@@ -15,9 +15,6 @@ const ReviewSchema = new mongoose.Schema({
type
:
String
,
type
:
String
,
// required: true,
// required: true,
},
},
content
:
{
type
:
String
,
},
keyword
:
{
keyword
:
{
type
:
Array
,
type
:
Array
,
// required: true,
// required: true,
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment