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
7af468a7
Commit
7af468a7
authored
Jan 25, 2021
by
Lee SeoYeon
Browse files
.
parent
b8fb805c
Changes
3
Show whitespace changes
Inline
Side-by-side
client/src/Pages/Search.js
View file @
7af468a7
...
@@ -18,28 +18,31 @@ function Search(props) {
...
@@ -18,28 +18,31 @@ function Search(props) {
const
[
imgUrl
,
setImgUrl
]
=
useState
([])
const
[
imgUrl
,
setImgUrl
]
=
useState
([])
const
[
association
,
setAssociation
]
=
useState
([])
const
[
association
,
setAssociation
]
=
useState
([])
const
getImg
=
()
=>
{
// console.log("search###############", search)
axios
.
get
(
`/api/search/imges?keyword=
${
search
}
`
)
const
getPlace
=
()
=>
{
axios
.
get
(
`/api/search/places?keyword=
${
search
}
`
)
.
then
(
res
=>
{
.
then
(
res
=>
{
console
.
log
(
"
imag
es=
"
,
res
.
data
)
console
.
log
(
"
plac
es=
"
,
res
.
data
)
set
ImgUrl
(
res
.
data
)
set
Place
(
res
.
data
)
})
})
.
catch
(
err
=>
{
.
catch
(
err
=>
{
console
.
log
(
'
search.
imag
es 에러 발생
'
,
err
)
console
.
log
(
'
search.
plac
es 에러 발생
'
,
err
)
})
})
}
}
const
get
Place
=
()
=>
{
const
get
Img
=
()
=>
{
axios
.
get
(
`/api/search/
plac
es?keyword=
${
search
}
`
)
axios
.
get
(
`/api/search/
img
es?keyword=
${
search
}
`
)
.
then
(
res
=>
{
.
then
(
res
=>
{
console
.
log
(
"
plac
es=
"
,
res
.
data
)
console
.
log
(
"
imag
es=
"
,
res
.
data
)
set
Place
(
res
.
data
)
set
ImgUrl
(
res
.
data
)
})
})
.
catch
(
err
=>
{
.
catch
(
err
=>
{
console
.
log
(
'
search.
plac
es 에러 발생
'
,
err
)
console
.
log
(
'
search.
imag
es 에러 발생
'
,
err
)
})
})
}
}
const
getAssociation
=
()
=>
{
const
getAssociation
=
()
=>
{
axios
.
get
(
`/api/search/association?keyword=
${
search
}
`
)
axios
.
get
(
`/api/search/association?keyword=
${
search
}
`
)
.
then
(
res
=>
{
.
then
(
res
=>
{
...
...
server/controllers/place.controller.js
View file @
7af468a7
...
@@ -37,7 +37,7 @@ const searchImg = async (req, res) => {
...
@@ -37,7 +37,7 @@ const searchImg = async (req, res) => {
let
DuplicateCheckImg
=
await
Places
.
findOne
({
name
:
req
.
query
.
keyword
})
let
DuplicateCheckImg
=
await
Places
.
findOne
({
name
:
req
.
query
.
keyword
})
if
(
DuplicateCheckImg
)
{
if
(
DuplicateCheckImg
.
img
!==
"
https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd
"
)
{
if
(
DuplicateCheckImg
.
img
!==
"
https://t1.daumcdn.net/thumb/R600x0/?fname=http%3A%2F%2Ft1.daumcdn.net%2Fqna%2Fimage%2F4b035cdf8372d67108f7e8d339660479dfb41bbd
"
)
{
res
.
send
(
DuplicateCheckImg
)
res
.
send
(
DuplicateCheckImg
)
console
.
log
(
"
333333333333333333333333333IMG@@@@@@@@@@@@@@@@@@@ 기존이미지줄력중
"
)
console
.
log
(
"
333333333333333333333333333IMG@@@@@@@@@@@@@@@@@@@ 기존이미지줄력중
"
)
...
@@ -52,20 +52,22 @@ const searchImg = async (req, res) => {
...
@@ -52,20 +52,22 @@ const searchImg = async (req, res) => {
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
'
)
axios
.
get
(
imgUrl
)
.
then
(
async
(
response
)
=>
{
const
html
=
response
.
data
let
name
=
req
.
query
.
keyword
let
$1
=
cheerio
.
load
(
html
);
//사진만 업데이트
//사진만 업데이트
let
Place
=
await
Places
.
findOne
({
name
:
req
.
query
.
keyword
})
let
Place
=
await
Places
.
findOne
({
name
:
req
.
query
.
keyword
})
Place
.
times
.
push
(
new
Date
().
toLocaleString
())
Place
.
times
.
push
(
new
Date
().
toLocaleString
())
await
Places
.
updateOne
({
name
:
req
.
query
.
keyword
},
{
img
:
images
,
times
:
Place
.
times
})
await
Places
.
updateOne
({
name
:
req
.
query
.
keyword
},
{
img
:
images
,
times
:
Place
.
times
})
res
.
send
(
images
)
res
.
send
(
images
)
})
})
}
else
{
}
else
{
console
.
log
(
"
IMG에러
"
)
console
.
log
(
"
IMG에러
"
)
}
}
}
...
@@ -77,12 +79,13 @@ const searchAssociation = async (req, res) => {
...
@@ -77,12 +79,13 @@ const searchAssociation = async (req, res) => {
// if (!Place) {
// if (!Place) {
// res.send([])
// res.send([])
// }
// }
if
(
!
Place
)
{
res
.
status
(
404
).
send
({
error
:
"
Place.address is null
"
})
}
else
{
let
addresse
=
Place
.
address
.
split
(
'
'
)[
0
]
let
addresse
=
Place
.
address
.
split
(
'
'
)[
0
]
let
AssociationsId
=
[]
let
addressPlaces
=
new
RegExp
(
`
${
addresse
}
`
)
let
responsePlaces
=
await
Places
.
find
({
address
:
addressPlaces
})
res
.
send
(
responsePlaces
)
let
AssociationsId
=
[]
let
AssociationsId
=
[]
let
addressPlaces
=
new
RegExp
(
`
${
addresse
}
`
)
let
addressPlaces
=
new
RegExp
(
`
${
addresse
}
`
)
console
.
log
(
"
여기보세요
"
,
addressPlaces
)
console
.
log
(
"
여기보세요
"
,
addressPlaces
)
...
...
server/controllers/review.controller.js
View file @
7af468a7
import
Review
from
'
../models/Review.js
'
import
Review
from
'
../models/Review.js
'
import
cheerio
from
"
cheerio
"
;
import
cheerio
from
"
cheerio
"
;
import
fs
from
'
fs
'
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
const
search
=
async
(
req
,
res
,
next
)
=>
{
const
search
=
async
(
req
,
res
,
next
)
=>
{
//**************************구글 크롤링 할 때************************/
console
.
log
(
"
1
"
)
for
(
let
i
=
1
;
(
req
.
reviews
).
length
>
10
;
i
++
)
{
try
{
try
{
console
.
log
(
"
2
"
)
let
reviews
=
[]
let
reviews
=
[]
let
content
=
[]
let
content
=
[]
// Review.find()
const
url
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
query
.
keyword
)
+
"
+site%3Atistory.com&page_no=
"
+
i
const
url
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
params
.
search
)
+
"
+site%3Atistory.com&page_no=1
"
const
response1
=
await
axios
.
get
(
url
)
const
response1
=
await
axios
.
get
(
url
)
fs
.
writeFileSync
(
"
googleSearch
"
,
response1
.
data
,
{
encoding
:
'
utf-8
'
})
// console.log(response1.data)
// console.log(response1.data)
const
$1
=
cheerio
.
load
(
response1
.
data
);
//cheerio? reponse1의 데이터를 로드하는거
const
$1
=
cheerio
.
load
(
response1
.
data
);
$1
(
'
.kCrYT
'
).
each
(
async
function
(
i
)
{
$1
(
'
.kCrYT
'
).
each
(
async
function
(
i
)
{
const
title
=
$1
(
this
).
find
(
'
h3
'
).
text
()
//타이틀에 텍스트 안에 h3값을 찾는다?
console
.
log
(
"
3
"
)
const
title
=
$1
(
this
).
find
(
'
h3
'
).
text
()
const
searchParams
=
new
URLSearchParams
(
$1
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
));
const
searchParams
=
new
URLSearchParams
(
$1
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
));
const
link
=
searchParams
.
get
(
"
/url?q
"
)
const
link
=
searchParams
.
get
(
"
/url?q
"
)
const
summary
=
$1
(
this
).
find
(
'
.s3v9rd
'
).
find
(
'
.s3v9rd
'
).
text
()
const
summary
=
$1
(
this
).
find
(
'
.s3v9rd
'
).
find
(
'
.s3v9rd
'
).
text
()
Review
.
find
({
link
:
link
},
function
(
err
,
review
)
{
if
(
!
review
)
{
content
.
push
(
getReview
(
link
))
content
.
push
(
getReview
(
link
))
if
(
title
)
{
//타이틀일때 리뷰에 [i] 를 넣었을 때 타이틀, 링크값 설정
if
(
title
)
{
reviews
[
i
]
=
{
title
:
title
,
link
:
link
}
reviews
[
i
]
=
{
title
:
title
,
link
:
link
}
}
else
if
(
summary
)
{
}
else
if
(
summary
)
{
reviews
[
i
-
1
]
=
{
...
reviews
[
i
-
1
],
summary
:
summary
}
reviews
[
i
-
1
]
=
{
...
reviews
[
i
-
1
],
summary
:
summary
}
reviews
=
reviews
.
filter
(
e
=>
e
)
reviews
=
reviews
.
filter
(
e
=>
e
)
}
}
}
})
})
})
const
promiseReview
=
await
Promise
.
all
(
content
)
let
promiseReview
=
await
Promise
.
all
(
content
)
promiseReview
=
promiseReview
.
filter
(
e
=>
typeof
(
e
)
===
'
string
'
)
reviews
.
forEach
(
async
(
review
,
i
)
=>
{
reviews
.
forEach
(
async
(
review
,
i
)
=>
{
console
.
log
(
"
4
"
)
review
[
"
content
"
]
=
promiseReview
[
i
]
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
)
res
.
send
(
reviews
)
}
catch
(
error
)
{
}
catch
(
error
)
{
// console.log(error)
console
.
log
(
"
6
"
)
// res.send(error)
console
.
log
(
error
)
res
.
send
(
error
)
}
}
}
}
}
...
@@ -72,5 +82,19 @@ const getReview = async (link) => {
...
@@ -72,5 +82,19 @@ const getReview = async (link) => {
return
content
return
content
}
}
export
default
{
search
,
getReview
}
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()
// })
}
export
default
{
search
,
find
}
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