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
eba09f3a
Commit
eba09f3a
authored
Jan 26, 2021
by
Kim, Chaerin
Browse files
.
parent
b4b32464
Changes
4
Show whitespace changes
Inline
Side-by-side
client/src/Components/Place.js
View file @
eba09f3a
...
@@ -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 @
eba09f3a
...
@@ -17,7 +17,6 @@ function Search(props) {
...
@@ -17,7 +17,6 @@ function Search(props) {
const
[
place
,
setPlace
]
=
useState
([{
name
:
""
,
category
:
""
,
address
:
""
}])
const
[
place
,
setPlace
]
=
useState
([{
name
:
""
,
category
:
""
,
address
:
""
}])
const
[
imgUrl
,
setImgUrl
]
=
useState
([])
const
[
imgUrl
,
setImgUrl
]
=
useState
([])
const
[
association
,
setAssociation
]
=
useState
([])
const
[
association
,
setAssociation
]
=
useState
([])
const
getImg
=
()
=>
{
const
getImg
=
()
=>
{
axios
.
get
(
`/api/search/imges?keyword=
${
search
}
`
)
axios
.
get
(
`/api/search/imges?keyword=
${
search
}
`
)
.
then
(
res
=>
{
.
then
(
res
=>
{
...
@@ -57,6 +56,9 @@ function Search(props) {
...
@@ -57,6 +56,9 @@ function Search(props) {
getPlace
()
getPlace
()
getImg
()
getImg
()
getAssociation
()
getAssociation
()
getPlace
()
getImg
()
if
(
window
.
innerWidth
<
960
)
{
if
(
window
.
innerWidth
<
960
)
{
setMobile
(
true
)
setMobile
(
true
)
}
else
{
}
else
{
...
@@ -64,11 +66,16 @@ function Search(props) {
...
@@ -64,11 +66,16 @@ function Search(props) {
}
}
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)
}
}
},
[
s
earch
]);
},
[
s
tate
]);
const
places
=
[{
const
places
=
[{
...
@@ -114,7 +121,7 @@ function Search(props) {
...
@@ -114,7 +121,7 @@ function Search(props) {
}
}
const
handleSubmit
=
(
e
)
=>
{
const
handleSubmit
=
(
e
)
=>
{
//
e.preventDefault()
e
.
preventDefault
()
setState
(
true
);
setState
(
true
);
}
}
...
...
server/controllers/review.controller.js
View file @
eba09f3a
...
@@ -4,91 +4,67 @@ import axios from 'axios';
...
@@ -4,91 +4,67 @@ import axios from 'axios';
const
search
=
async
(
req
,
res
,
next
)
=>
{
const
search
=
async
(
req
,
res
,
next
)
=>
{
console
.
log
(
"
1
"
)
console
.
log
(
"
1
"
)
for
(
let
i
=
1
;
(
req
.
reviews
).
length
>
10
;
i
++
)
{
try
{
try
{
console
.
log
(
"
2
"
)
for
(
let
j
=
1
;
j
<
2
;
j
++
)
{
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
(
!
review
)
{
content
.
push
(
getReview
(
link
))
if
(
title
)
{
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
)
}
}
}
})
})
})
let
promiseReview
=
await
Promise
.
all
(
content
)
reviews
.
forEach
((
review
,
i
)
=>
{
promiseReview
=
promiseReview
.
filter
(
e
=>
typeof
(
e
)
===
'
string
'
)
Review
.
findOne
({
link
:
review
.
link
},
async
function
(
err
,
reviewss
)
{
reviews
.
forEach
(
async
(
review
,
i
)
=>
{
console
.
log
(
"
4
"
)
console
.
log
(
"
4
"
)
review
[
"
content
"
]
=
promiseReview
[
i
]
const
reviews
=
new
Review
(
review
).
save
()
if
(
err
)
{
return
res
.
status
(
404
).
send
({
error
:
err
})
}
reviews
.
keyword
.
push
(
req
.
query
.
keyword
)
if
(
reviewss
)
{
req
.
reviews
.
push
(
reviews
)
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
)
{
}
catch
(
error
)
{
console
.
log
(
"
6
"
)
console
.
log
(
"
6
"
)
console
.
log
(
error
)
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
)
=>
{
if
(
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
()
}
return
content
}
}
const
find
=
(
req
,
res
,
next
)
=>
{
const
find
=
(
req
,
res
,
next
)
=>
{
console
.
log
(
"
7
"
,
req
.
body
)
console
.
log
(
"
7
"
,
req
.
query
.
keyword
)
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
)
{
req
.
reviews
=
[]
if
(
reviews
)
{
if
(
reviews
)
{
if
(
reviews
.
length
>
10
)
if
(
reviews
.
length
>
10
)
{
res
.
send
(
reviews
,
{
db
:
true
})
res
.
status
(
200
).
send
({
review
:
reviews
,
db
:
true
})
}
req
.
reviews
=
reviews
req
.
reviews
=
reviews
}
}
next
()
next
()
...
...
server/models/Review.js
View file @
eba09f3a
...
@@ -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