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
Hide whitespace changes
Inline
Side-by-side
client/src/Components/Place.js
View file @
eba09f3a
...
...
@@ -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
)
...
...
client/src/Pages/Search.js
View file @
eba09f3a
...
...
@@ -17,7 +17,6 @@ function Search(props) {
const
[
place
,
setPlace
]
=
useState
([{
name
:
""
,
category
:
""
,
address
:
""
}])
const
[
imgUrl
,
setImgUrl
]
=
useState
([])
const
[
association
,
setAssociation
]
=
useState
([])
const
getImg
=
()
=>
{
axios
.
get
(
`/api/search/imges?keyword=
${
search
}
`
)
.
then
(
res
=>
{
...
...
@@ -57,6 +56,9 @@ function Search(props) {
getPlace
()
getImg
()
getAssociation
()
getPlace
()
getImg
()
if
(
window
.
innerWidth
<
960
)
{
setMobile
(
true
)
}
else
{
...
...
@@ -64,11 +66,16 @@ function Search(props) {
}
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)
}
},
[
s
earch
]);
},
[
s
tate
]);
const
places
=
[{
...
...
@@ -114,7 +121,7 @@ function Search(props) {
}
const
handleSubmit
=
(
e
)
=>
{
//
e.preventDefault()
e
.
preventDefault
()
setState
(
true
);
}
...
...
server/controllers/review.controller.js
View file @
eba09f3a
...
...
@@ -4,91 +4,67 @@ import axios from 'axios';
const
search
=
async
(
req
,
res
,
next
)
=>
{
console
.
log
(
"
1
"
)
for
(
let
i
=
1
;
(
req
.
reviews
).
length
>
10
;
i
++
)
{
try
{
console
.
log
(
"
2
"
)
try
{
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
))
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
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
)
}
})
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
)
=>
{
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
)
=>
{
console
.
log
(
"
7
"
,
req
.
body
)
console
.
log
(
"
7
"
,
req
.
query
.
keyword
)
const
keyword
=
req
.
query
.
keyword
if
(
req
.
body
.
db
)
{
next
()
}
Review
.
find
({
keyword
:{
$elemMatch
:
res
.
query
.
keyword
}
},
function
(
err
,
reviews
)
{
Review
.
find
({
keyword
:
keyword
},
function
(
err
,
reviews
)
{
req
.
reviews
=
[]
if
(
reviews
)
{
if
(
reviews
.
length
>
10
)
res
.
send
(
reviews
,
{
db
:
true
})
if
(
reviews
.
length
>
10
)
{
res
.
status
(
200
).
send
({
review
:
reviews
,
db
:
true
})
}
req
.
reviews
=
reviews
}
next
()
...
...
server/models/Review.js
View file @
eba09f3a
...
...
@@ -15,9 +15,6 @@ const ReviewSchema = new mongoose.Schema({
type
:
String
,
// required: true,
},
content
:
{
type
:
String
,
},
keyword
:
{
type
:
Array
,
// 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