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
b7e0b8ba
Commit
b7e0b8ba
authored
Jan 11, 2021
by
Kim, Chaerin
Browse files
?
parent
f9bcb8f6
Changes
11
Expand all
Show whitespace changes
Inline
Side-by-side
client/.eslintcache
View file @
b7e0b8ba
This diff is collapsed.
Click to expand it.
client/src/App.js
→
client/src/
Pages/
App.js
View file @
b7e0b8ba
import
React
,
{
useEffect
,
useState
}
from
'
react
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
import
ohuh
from
'
./ohuh.PNG
'
;
import
{
Container
,
Row
,
Form
,
Image
,
InputGroup
,
Button
,
Col
}
from
'
react-bootstrap
'
;
import
ohuh
from
'
.
.
/ohuh.PNG
'
;
import
{
Container
,
Row
,
Form
,
Image
,
InputGroup
,
Button
,
Col
,
FormControl
}
from
'
react-bootstrap
'
;
function
App
()
{
const
[
state
,
setState
]
=
useState
(
false
);
...
...
@@ -25,31 +25,28 @@ function App() {
return
(
<
Container
className
=
"
vh-100 d-flex justify-content-md-center align-items-center
"
>
<
Col
md
=
{
6
}
lassName
=
"
d-flex justify-content-center
"
>
<
Row
style
=
{{
marginBottom
:
20
}}
>
<
Image
src
=
{
ohuh
}
/
>
<
/Row
>
<
Row
style
=
{{
marginBottom
:
500
}}
>
<
Form
className
=
"
vw-100
"
onSubmit
=
{
handleSubmit
}
>
<
InputGroup
>
<
Form
.
Control
size
=
"
lg
"
<
Container
className
=
"
vh-100
"
>
<
Row
className
=
"
d-flex justify-content-md-center
"
>
<
Col
md
=
{
6
}
className
=
"
mt-5
"
>
<
Image
src
=
{
ohuh
}
fluid
/>
<
/Col
>
<
Col
lg
=
{{
span
:
10
,
offset
:
1
}}
>
<
InputGroup
size
=
"
lg
"
lg
=
{
6
}
xs
=
{
4
}
fluid
>
<
FormControl
className
=
"
d-flex justify-content-lg-center
"
placeholder
=
"
검색어를 입력하세요.
"
aria
-
label
=
"
Large
"
aria
-
describedby
=
"
inputGroup-sizing-sm
"
onChange
=
{
handleChange
}
/
>
<
InputGroup
.
Append
>
<
Button
type
=
'
submit
'
variant
=
"
outline-secondary
"
>
검색
<
/Button
>
<
Button
variant
=
"
outline-secondary
"
onClick
=
{
handleSubmit
}
>
검색
<
/Button
>
<
/InputGroup.Append
>
<
/InputGroup
>
<
/Form
>
<
/Row
>
<
/Col
>
<
/Row
>
<
/Container
>
);
}
...
...
client/src/Search.js
→
client/src/
Pages/
Search.js
View file @
b7e0b8ba
import
React
,
{
useState
,
useEffect
}
from
'
react
'
;
import
{
Link
,
Redirect
}
from
'
react-router-dom
'
;
import
ohuh
from
'
./ohuh-sm.PNG
'
;
import
Place
from
'
./Components/Place
'
;
import
ohuh
from
'
.
.
/ohuh-sm.PNG
'
;
import
Place
from
'
.
.
/Components/Place
'
;
import
{
Container
,
Form
,
Row
,
Col
,
Card
,
Image
,
InputGroup
,
FormControl
,
Button
,
Pagination
}
from
'
react-bootstrap
'
;
import
Paginations
from
'
./Components/Paginations
'
;
import
Paginations
from
'
.
.
/Components/Paginations
'
;
function
Search
(
props
)
{
const
endPage
=
10
;
...
...
client/src/index.js
View file @
b7e0b8ba
...
...
@@ -2,8 +2,8 @@ import React from 'react';
import
ReactDOM
from
'
react-dom
'
;
import
'
./index.css
'
;
import
'
bootstrap/dist/css/bootstrap.min.css
'
;
import
App
from
'
./App
'
;
import
Search
from
'
./Search
'
;
import
App
from
'
./
Pages/
App
'
;
import
Search
from
'
./
Pages/
Search
'
;
import
axios
from
'
axios
'
;
import
reportWebVitals
from
'
./reportWebVitals
'
;
import
{
...
...
package.json
View file @
b7e0b8ba
...
...
@@ -5,6 +5,7 @@
"main"
:
"index.js"
,
"type"
:
"module"
,
"scripts"
:
{
"dev"
:
"nodemon server/server.js"
,
"test"
:
"echo
\"
Error: no test specified
\"
&& exit 1"
},
"repository"
:
{
...
...
server/controllers/place.controller.js
View file @
b7e0b8ba
import
Place
from
'
../models/Place.js
'
import
cheerio
from
'
cheerio
'
const
signup
=
async
(
req
,
res
)
=>
{
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
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,
// })
// }
}
export
default
{
signup
,
search
}
\ No newline at end of file
server/controllers/review.controller.js
View file @
b7e0b8ba
...
...
@@ -12,24 +12,30 @@ const signup = async (req, res) => {
}
const
search
=
async
(
req
,
res
)
=>
{
console
.
log
(
req
.
params
.
search
)
console
.
log
(
"
req
"
,
req
)
const
url
=
"
https://www.google.com/search?q=%ED%95%9C%EB%9D%BC%EC%82%B0%20site%3Atistory.com&oq=tistory&aqs=chrome..69i57j0l4j69i60l3.1746j0j4&sourceid=chrome&ie=UTF-8&ved=2ahUKEwis_bSFz4buAhWVdXAKHU0tBaoQ2wF6BAgIEAE&ei=T1D1X-yZD5XrwQPN2pTQCg
"
const
url
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
params
.
search
)
+
"
+site%3Atistory.com
"
+
'
&page_no=1
'
request
(
url
)
.
then
(
anyToUtf8
)
.
then
((
html
)
=>
{
// fs.writeFileSync("googlez.txt", '\ufeff' + html, { encoding: 'utf8' });
let
$
=
cheerio
.
load
(
html
,
null
,
false
);
let
places
=
[]
$
(
'
.kCrYT
'
).
each
(
function
(
i
)
{
const
review
=
await
Review
.
findOne
({
link
:
$
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
)
})
if
(
!
user
)
{
const
newReview
=
await
new
Review
({
name
,
email
,
password
:
hash
}).
save
()
}
places
[
i
]
=
{
title
:
$
(
this
).
find
(
'
h3
'
).
text
(),
link
:
$
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
),
summary
:
$
(
this
).
find
(
'
.s3v9rd
'
).
text
(),
summary
:
$
(
this
).
find
(
'
.s3v9rd
'
).
text
(),
}
})
// console.log(places)
res
.
send
(
places
)
})
...
...
@@ -39,8 +45,6 @@ const search = async (req, res) => {
const
iconv
=
new
Iconv
(
encoding
,
"
utf-8//translit//ignore
"
);
return
iconv
.
convert
(
str
).
toString
();
}
// try {
// const newPlace = await new Place({
// name: req.params.search,
...
...
@@ -51,4 +55,6 @@ const search = async (req, res) => {
// }
}
const
export
default
{
signup
,
search
}
\ No newline at end of file
server/models/Review.js
View file @
b7e0b8ba
...
...
@@ -3,14 +3,17 @@ import mongoose from 'mongoose'
const
{
String
}
=
mongoose
.
Schema
.
Types
const
ReviewSchema
=
new
mongoose
.
Schema
({
title
:
{
type
:
String
,
},
link
:
{
type
:
String
,
required
:
true
,
unique
:
true
,
},
content
:
{
summary
:
{
type
:
String
,
required
:
true
,
unique
:
true
,
},
keyword
:
{
type
:
Array
,
...
...
server/routes/place.routes.js
View file @
b7e0b8ba
import
express
from
'
express
'
import
place
from
'
../controllers/place.controller.js
'
const
router
=
express
.
Router
()
router
.
route
(
'
/api/search/:search
'
)
.
post
(
place
.
signup
)
.
get
(
place
.
search
)
export
default
router
\ No newline at end of file
server/scraper.js
0 → 100644
View file @
b7e0b8ba
import
axios
from
"
axios
"
;
import
cheerio
from
"
cheerio
"
;
import
express
from
'
express
'
;
import
request
from
'
request-promise
'
import
jschardet
from
'
jschardet
'
import
iconv
from
'
iconv
'
import
fs
from
'
fs
'
const
Iconv
=
iconv
.
Iconv
const
app
=
express
()
app
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
const
url
=
"
https://100mountain.tistory.com/117
"
request
({
url
:
url
,
encoding
:
null
,
})
.
then
(
anyToUtf8
)
.
then
((
html
)
=>
{
// fs.writeFileSync("test.txt", '\ufeff' + html, {encoding: 'utf8'});
let
$
=
cheerio
.
load
(
html
,
null
,
false
);
let
places
=
[]
$
(
'
div.tt_article_useless_p_margin
'
).
each
(
function
()
{
console
.
log
(
"
title
"
,
$
(
this
).
find
(
'
p
'
).
text
())
});
console
.
log
(
"
places
"
,
places
)
})
function
anyToUtf8
(
str
)
{
const
{
encoding
}
=
jschardet
.
detect
(
str
);
const
iconv
=
new
Iconv
(
encoding
,
"
utf-8//translit//ignore
"
);
return
iconv
.
convert
(
str
).
toString
();
}
})
app
.
listen
(
3001
,
()
=>
{
console
.
log
(
'
Server is listening on port 3001
'
)
})
\ No newline at end of file
server/scraperss.js
0 → 100644
View file @
b7e0b8ba
import
axios
from
"
axios
"
;
import
cheerio
from
"
cheerio
"
;
import
express
from
'
express
'
;
import
request
from
'
request-promise
'
import
jschardet
from
'
jschardet
'
import
iconv
from
'
iconv
'
import
fs
from
'
fs
'
const
Iconv
=
iconv
.
Iconv
const
app
=
express
()
app
.
get
(
'
/
'
,
(
req
,
res
)
=>
{
const
url
=
"
https://www.google.com/search?q=%ED%95%9C%EB%9D%BC%EC%82%B0%20site%3Atistory.com&oq=tistory&aqs=chrome..69i57j0l4j69i60l3.1746j0j4&sourceid=chrome&ie=UTF-8&ved=2ahUKEwis_bSFz4buAhWVdXAKHU0tBaoQ2wF6BAgIEAE&ei=T1D1X-yZD5XrwQPN2pTQCg
"
request
(
url
)
.
then
(
anyToUtf8
)
.
then
((
html
)
=>
{
// fs.writeFileSync("googlez.txt", '\ufeff' + html, { encoding: 'utf8' });
let
$
=
cheerio
.
load
(
html
,
null
,
false
);
let
places
=
[]
$
(
'
.kCrYT
'
).
each
(
function
(
i
)
{
places
[
i
]
=
{
title
:
$
(
this
).
find
(
'
h3
'
).
text
(),
link
:
$
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
),
summary
:
$
(
this
).
text
(),
}
})
console
.
log
(
places
)
})
function
anyToUtf8
(
str
)
{
const
{
encoding
}
=
jschardet
.
detect
(
str
);
console
.
log
(
"
source encoding =
"
+
encoding
);
const
iconv
=
new
Iconv
(
encoding
,
"
utf-8//translit//ignore
"
);
return
iconv
.
convert
(
str
).
toString
();
}
res
.
send
(
"
안녕
"
)
})
app
.
listen
(
3001
,
()
=>
{
console
.
log
(
'
Server is listening on port 3001
'
)
})
\ No newline at end of file
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