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
0dfdacbe
Commit
0dfdacbe
authored
Jan 14, 2021
by
baesangjune
Browse files
.
parent
3515ba65
Changes
8
Expand all
Hide whitespace changes
Inline
Side-by-side
client/.eslintcache
View file @
0dfdacbe
This diff is collapsed.
Click to expand it.
client/src/Components/Place.js
View file @
0dfdacbe
...
@@ -19,6 +19,7 @@ function Place(props) {
...
@@ -19,6 +19,7 @@ function Place(props) {
getReview
();
getReview
();
},
[])
},
[])
return
(
return
(
<
Modal
{...
props
}
<
Modal
{...
props
}
size
=
"
xl
"
size
=
"
xl
"
...
...
client/src/Pages/Search.js
View file @
0dfdacbe
...
@@ -4,6 +4,7 @@ import ohuh from '../ohuh-sm.PNG';
...
@@ -4,6 +4,7 @@ import ohuh from '../ohuh-sm.PNG';
import
Place
from
'
../Components/Place
'
;
import
Place
from
'
../Components/Place
'
;
import
{
Container
,
Form
,
Row
,
Col
,
Card
,
Image
,
InputGroup
,
FormControl
,
Button
,
Pagination
}
from
'
react-bootstrap
'
;
import
{
Container
,
Form
,
Row
,
Col
,
Card
,
Image
,
InputGroup
,
FormControl
,
Button
,
Pagination
}
from
'
react-bootstrap
'
;
import
Paginations
from
'
../Components/Paginations
'
;
import
Paginations
from
'
../Components/Paginations
'
;
import
axios
from
'
axios
'
;
function
Search
(
props
)
{
function
Search
(
props
)
{
const
endPage
=
10
;
const
endPage
=
10
;
...
@@ -13,7 +14,25 @@ function Search(props) {
...
@@ -13,7 +14,25 @@ function Search(props) {
const
[
search
,
setSearch
]
=
useState
(
props
.
location
.
state
.
id
);
const
[
search
,
setSearch
]
=
useState
(
props
.
location
.
state
.
id
);
const
[
mobile
,
setMobile
]
=
useState
();
const
[
mobile
,
setMobile
]
=
useState
();
const
[
reviews
,
setReviews
]
=
useState
([])
const
getReview
=
()
=>
{
console
.
log
(
'
search
'
,
search
)
axios
.
get
(
`/api/search/
${
search
}
`
)
.
then
(
res
=>
{
console
.
log
(
"
res.data22222222=
"
,
res
.
data
)
setReviews
(
res
.
data
)
})
.
catch
(
err
=>
{
console
.
log
(
'
search.err발생
'
,
err
)
})
}
useEffect
(()
=>
{
useEffect
(()
=>
{
getReview
()
if
(
window
.
innerWidth
<
960
)
{
if
(
window
.
innerWidth
<
960
)
{
setMobile
(
true
)
setMobile
(
true
)
}
else
{
}
else
{
...
@@ -21,6 +40,11 @@ function Search(props) {
...
@@ -21,6 +40,11 @@ function Search(props) {
}
}
},
[]);
},
[]);
const
places
=
[{
const
places
=
[{
name
:
"
한라산(hallasan)
"
,
name
:
"
한라산(hallasan)
"
,
address
:
"
제주 서귀포시 토평동 산15-1
"
,
address
:
"
제주 서귀포시 토평동 산15-1
"
,
...
...
googlez.txt
View file @
0dfdacbe
This diff is collapsed.
Click to expand it.
server/controllers/place.controller.js
View file @
0dfdacbe
import
Place
from
'
../models/Place.js
'
import
Place
from
'
../models/Place.js
'
import
cheerio
from
'
cheerio
'
import
cheerio
from
'
cheerio
'
import
fs
from
'
fs
'
const
signup
=
async
(
req
,
res
)
=>
{
import
axios
from
'
axios
'
;
const
{
name
,
email
,
password
}
=
req
.
body
console
.
log
(
name
,
email
,
password
)
try
{
if
(
!
isLength
(
name
,
{
min
:
3
,
max
:
10
}))
{
return
res
.
status
(
422
).
send
(
'
Name must be 3-10 characters
'
)
}
const
newUser
=
await
new
User
({
name
,
email
,
password
}).
save
()
console
.
log
(
newUser
)
res
.
json
(
newUser
)
}
catch
(
error
)
{
console
.
log
(
error
)
res
.
status
(
500
).
send
(
'
User signup error
'
)
}
}
const
search
=
async
(
req
,
res
)
=>
{
const
search
=
async
(
req
,
res
)
=>
{
// 정보들 크롤링 해오고 아래에 넣어주기
const
url
=
"
https://section.blog.naver.com/Search/Post.nhn?keyword=
"
+
keyword
request
(
url
,
function
(
err
,
res
,
html
)
{
// URL로부터 가져온 페이지 소스가 html이란 변수에 담긴다.
if
(
!
err
)
{
var
$
=
cheerio
.
load
(
html
);
// 블로그 title 정보 가져오기
$
(
"
.entry-title > a
"
).
each
(
function
()
{
var
post
=
{
"
name
"
:
""
,
"
address
"
:
""
,
"
img
"
:
""
};
var
data
=
$
(
this
);
post
[
"
title
"
]
=
data
.
text
();
post
[
"
link
"
]
=
data
.
attr
(
"
href
"
);
});
}
})
// try {
// const newPlace = await new Place({
// name: req.params.search,
// address,
// img,
// })
console
.
log
(
"
여기까지 도착합니다.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"
)
// }
console
.
log
(
req
.
params
.
search
)
const
url
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
params
.
search
)
+
"
+site%3Atistory.com&page_no=1
"
const
editUrl
=
/
(
http
(
s
)?
:
\/\/)([
a-z0-9
\w]
+
\.
*
)
+
[
a-z0-9
]{2,4}
/gi
axios
.
get
(
url
)
.
then
((
response
)
=>
{
const
html
=
response
.
data
fs
.
writeFileSync
(
"
googlez.txt
"
,
html
,
{
encoding
:
'
utf8
'
});
let
$1
=
cheerio
.
load
(
html
);
let
reviews
=
[]
$1
(
'
.kCrYT
'
).
each
(
function
(
i
)
{
if
(
$1
(
this
).
find
(
'
h3
'
).
text
())
{
reviews
[
i
]
=
{
name
:
$1
(
this
).
find
(
'
h3
'
).
text
(),
link
:
(
$1
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
))
}
}
else
if
(
$1
(
this
).
find
(
'
.s3v9rd
'
).
find
(
'
.s3v9rd
'
).
text
())
{
reviews
[
i
-
1
]
=
{
...
reviews
[
i
-
1
],
address
:
$1
(
this
).
find
(
'
.s3v9rd
'
).
find
(
'
.s3v9rd
'
).
text
()
}
reviews
=
reviews
.
filter
(
e
=>
e
)
}
})
console
.
log
(
"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"
,
reviews
)
res
.
send
(
reviews
)
})
}
}
export
default
{
signup
,
search
}
export
default
{
search
}
server/controllers/review.controller.js
View file @
0dfdacbe
import
Review
from
'
../models/Review.js
'
import
Review
from
'
../models/Review.js
'
import
cheerio
from
"
cheerio
"
;
import
cheerio
from
"
cheerio
"
;
import
jschardet
from
'
jschardet
'
import
jschardet
from
'
jschardet
'
// import iconv from 'iconv'
import
fs
from
'
fs
'
import
fs
from
'
fs
'
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
// const Iconv = iconv.Iconv
const
search
=
async
(
req
,
res
)
=>
{
const
search
=
async
(
req
,
res
)
=>
{
const
url
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
params
.
search
)
+
"
+site%3Atistory.com&page_no=1
"
const
url
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
params
.
search
)
+
"
+site%3Atistory.com&page_no=1
"
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
)
axios
.
get
(
url
)
// .then(anyToUtf8)
.
then
((
response
)
=>
{
.
then
((
response
)
=>
{
const
html
=
response
.
data
const
html
=
response
.
data
fs
.
writeFileSync
(
"
googlez.txt
"
,
html
,
{
encoding
:
'
utf8
'
});
fs
.
writeFileSync
(
"
googlez.txt
"
,
html
,
{
encoding
:
'
utf8
'
});
...
@@ -25,32 +22,10 @@ const search = async (req, res) => {
...
@@ -25,32 +22,10 @@ const search = async (req, res) => {
reviews
=
reviews
.
filter
(
e
=>
e
)
reviews
=
reviews
.
filter
(
e
=>
e
)
}
}
})
})
// reviews.forEach((review, i) => {
// axios.get(review.link)
// .then((html) => {
// let $2 = cheerio.load(html.data);
// $2('').each(function(i){
// review.content($2(this).find(''.text()))
// })
// })
// })
console
.
log
(
"
*******************************************
"
,
reviews
)
console
.
log
(
"
*******************************************
"
,
reviews
)
res
.
send
(
reviews
)
res
.
send
(
reviews
)
})
})
// function anyToUtf8(str) {
// const { encoding } = jschardet.detect(str); // 웹페이지 문서의 인코딩 타입을 확인
// const iconv = new Iconv(encoding, "utf-8//translit//ignore"); // euc-kr 인코딩변환
// return iconv.convert(str).toString();
// }
// try {
// const newPlace = await new Place({
// name: req.params.search,
// address,
// img,
// })
// }
}
}
...
...
server/routes/place.routes.js
View file @
0dfdacbe
...
@@ -4,7 +4,6 @@ import place from '../controllers/place.controller.js'
...
@@ -4,7 +4,6 @@ import place from '../controllers/place.controller.js'
const
router
=
express
.
Router
()
const
router
=
express
.
Router
()
router
.
route
(
'
/api/search/:search
'
)
router
.
route
(
'
/api/search/:search
'
)
.
post
(
place
.
signup
)
.
get
(
place
.
search
)
.
get
(
place
.
search
)
export
default
router
export
default
router
\ No newline at end of file
server/server.js
View file @
0dfdacbe
import
express
from
'
express
'
import
express
from
'
express
'
import
connectDb
from
'
./utils/connectDb.js
'
import
connectDb
from
'
./utils/connectDb.js
'
//
import placeRouter from './routes/place.routes.js'
import
placeRouter
from
'
./routes/place.routes.js
'
import
reviewRouter
from
'
./routes/review.routes.js
'
import
reviewRouter
from
'
./routes/review.routes.js
'
connectDb
()
connectDb
()
...
@@ -9,7 +9,7 @@ const app = express()
...
@@ -9,7 +9,7 @@ const app = express()
app
.
use
(
express
.
json
())
app
.
use
(
express
.
json
())
//
app.use(placeRouter)
app
.
use
(
placeRouter
)
app
.
use
(
reviewRouter
)
app
.
use
(
reviewRouter
)
app
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
app
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
...
...
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