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
63b59e7d
Commit
63b59e7d
authored
Jan 18, 2021
by
baesangjune
Browse files
.
parent
05f1c0e5
Changes
6
Expand all
Show whitespace changes
Inline
Side-by-side
client/.eslintcache
View file @
63b59e7d
This diff is collapsed.
Click to expand it.
client/src/Pages/Search.js
View file @
63b59e7d
...
@@ -13,7 +13,7 @@ function Search(props) {
...
@@ -13,7 +13,7 @@ function Search(props) {
const
[
showSet
,
setShowSet
]
=
useState
([
false
,
false
,
false
,
false
]);
const
[
showSet
,
setShowSet
]
=
useState
([
false
,
false
,
false
,
false
]);
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
[
place
,
setPlace
]
=
useState
([])
const
[
place
,
setPlace
]
=
useState
([
{
name
:
""
,
category
:
""
,
address
:
""
}
])
const
[
imgUrl
,
setImgUrl
]
=
useState
([])
const
[
imgUrl
,
setImgUrl
]
=
useState
([])
const
getImg
=
()
=>
{
const
getImg
=
()
=>
{
...
@@ -473,9 +473,9 @@ function Search(props) {
...
@@ -473,9 +473,9 @@ function Search(props) {
setState
(
true
);
setState
(
true
);
}
}
function
paginate
(
items
,
pageNumber
)
{
function
paginate
(
items
,
pageNumber
,
itemNumber
)
{
const
page
=
[];
const
page
=
[];
const
startIndex
=
(
pageNumber
-
1
)
*
4
const
startIndex
=
(
pageNumber
-
1
)
*
itemNumber
for
(
var
i
=
0
;
i
<
4
;
i
++
)
{
for
(
var
i
=
0
;
i
<
4
;
i
++
)
{
page
.
push
(
items
[(
startIndex
+
i
)])
page
.
push
(
items
[(
startIndex
+
i
)])
}
}
...
@@ -483,7 +483,7 @@ function Search(props) {
...
@@ -483,7 +483,7 @@ function Search(props) {
}
}
const
pagePlace
=
paginate
(
places
,
index
)
const
pagePlace
=
paginate
(
places
,
index
,
1
)
return
(
return
(
<
Container
>
<
Container
>
...
@@ -504,7 +504,25 @@ function Search(props) {
...
@@ -504,7 +504,25 @@ function Search(props) {
<
/InputGroup
>
<
/InputGroup
>
<
/Form
>
<
/Form
>
<
/Row
>
<
/Row
>
<
Image
src
=
{
imgUrl
}
/
>
<
Col
md
=
{
6
}
>
<
Card
align
=
"
center
"
border
=
"
info
"
style
=
{{
margin
:
"
3%
"
}}
>
<
Card
.
Title
style
=
{{
margin
:
"
3%
"
,
fontSize
:
'
200%
'
,
fontWeight
:
'
bold
'
}}
>
{
place
[
0
].
name
}
<
/Card.Title
>
<
Card
.
Img
variant
=
"
top
"
style
=
{{
padding
:
"
5%
"
,
width
:
"
100%
"
,
height
:
"
340px
"
}}
src
=
{
imgUrl
}
/
>
<
Card
.
Body
>
<
Card
.
Text
style
=
{{
overflow
:
'
auto
'
,
fontSize
:
'
25px
'
,
width
:
'
100%
'
,
height
:
"
80px
"
}}
>
{
place
[
0
].
address
}{
place
[
0
].
category
}
<
/Card.Text
>
<
Button
variant
=
"
primary
"
onClick
=
{()
=>
{
// const showArr = [false, false, false, false]
// showArr[index] = true
// setShowSet(showArr)
}}
>
{
place
[
0
].
name
}
자세히
살펴보기
<
/Button
>
{
/* <Place search={place} show={show} onHide={() => setShowSet([false, false, false, false])} /> */
}
<
/Card.Body
>
<
/Card
>
<
/Col
>
<
Row
className
=
"
d-flex flex-wrap
"
>
<
Row
className
=
"
d-flex flex-wrap
"
>
{
pagePlace
.
map
((
place
,
index
)
=>
{
{
pagePlace
.
map
((
place
,
index
)
=>
{
return
(
return
(
...
...
googlez.txt
View file @
63b59e7d
This diff is collapsed.
Click to expand it.
server/controllers/place.controller.js
View file @
63b59e7d
import
Place
from
'
../models/Place.js
'
import
Place
s
from
'
../models/Place.js
'
import
cheerio
from
'
cheerio
'
import
cheerio
from
'
cheerio
'
import
fs
from
'
fs
'
import
fs
from
'
fs
'
import
axios
from
'
axios
'
;
import
axios
from
'
axios
'
;
const
searchPlace
=
async
(
req
,
res
)
=>
{
const
searchPlace
=
async
(
req
,
res
)
=>
{
console
.
log
(
"
여기까지는 옵니다~
"
)
const
url
=
"
https://
www.google.com/search?q=
"
+
encodeURI
(
req
.
params
.
search
)
+
"
+site%3Atistory.com&page_no=1
"
const
url
=
"
https://
search.naver.com/search.naver?sm=tab_hty.top&where=nexearch&query=
"
+
encodeURI
(
req
.
params
.
search
)
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
((
response
)
=>
{
.
then
(
async
(
response
)
=>
{
const
html
=
response
.
data
const
html
=
response
.
data
let
$1
=
cheerio
.
load
(
html
);
let
$1
=
cheerio
.
load
(
html
);
let
places
=
[]
let
places
=
{}
$1
(
'
.kCrYT
'
).
each
(
function
(
i
)
{
$1
(
'
.ct_box_area
'
).
each
(
function
(
i
)
{
// console.log($1('.biz_name').text())
// console.log($1('.category').text())
// console.log($1('.addr').text())
// console.log($1('.t?ime highlight').text())
if
(
$1
(
this
).
find
(
'
h3
'
).
text
())
{
places
[
i
]
=
{
name
:
$1
(
this
).
find
(
'
h3
'
).
text
(),
link
:
(
$1
(
this
).
find
(
'
a
'
).
attr
(
'
href
'
))
}
places
[
i
]
=
{
name
:
$1
(
'
.biz_name
'
).
text
(),
category
:
$1
(
'
.category
'
).
text
(),
address
:
$1
(
'
.addr
'
).
text
()
}
}
else
if
(
$1
(
this
).
find
(
'
.s3v9rd
'
).
find
(
'
.s3v9rd
'
).
text
())
{
places
[
i
-
1
]
=
{
...
places
[
i
-
1
],
address
:
$1
(
this
).
find
(
'
.s3v9rd
'
).
find
(
'
.s3v9rd
'
).
text
()
}
places
=
places
.
filter
(
e
=>
e
)
}
})
})
console
.
log
(
"
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
"
,
places
)
// 값이 비어있거나 에러가 생겼을 때를 대비해 try catch를 해야함
const
newPlaces
=
await
new
Places
(
places
[
0
]
).
save
()
res
.
send
(
places
)
res
.
send
(
places
)
})
})
}
}
...
@@ -32,8 +33,9 @@ const searchImg = async (req, res) => {
...
@@ -32,8 +33,9 @@ const searchImg = async (req, res) => {
const
imgUrl
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
params
.
search
)
+
"
+site:tistory.com/&sxsrf=ALeKk023Dv08KQDodRmpB5222lQuzw2Vaw:1610612821100&source=lnms&tbm=isch
"
const
imgUrl
=
"
https://www.google.com/search?q=
"
+
encodeURI
(
req
.
params
.
search
)
+
"
+site:tistory.com/&sxsrf=ALeKk023Dv08KQDodRmpB5222lQuzw2Vaw:1610612821100&source=lnms&tbm=isch
"
axios
.
get
(
imgUrl
)
axios
.
get
(
imgUrl
)
.
then
((
response
)
=>
{
.
then
(
async
(
response
)
=>
{
const
html
=
response
.
data
const
html
=
response
.
data
let
name
=
req
.
params
.
search
let
$1
=
cheerio
.
load
(
html
);
let
$1
=
cheerio
.
load
(
html
);
let
images
=
$1
(
'
.RAyV4b
'
).
find
(
'
img
'
).
attr
(
'
src
'
)
let
images
=
$1
(
'
.RAyV4b
'
).
find
(
'
img
'
).
attr
(
'
src
'
)
...
@@ -45,6 +47,8 @@ const searchImg = async (req, res) => {
...
@@ -45,6 +47,8 @@ const searchImg = async (req, res) => {
// })
// })
// console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%', images)
// console.log('%%%%%%%%%%%%%%%%%%%%%%%%%%%', images)
res
.
send
(
images
)
res
.
send
(
images
)
const
newPlaces
=
await
new
Places
(
name
,
images
).
save
()
})
})
}
}
...
...
server/models/Place.js
View file @
63b59e7d
...
@@ -25,8 +25,11 @@ const PlaceSchema = new mongoose.Schema({
...
@@ -25,8 +25,11 @@ const PlaceSchema = new mongoose.Schema({
type
:
Array
,
type
:
Array
,
required
:
true
,
required
:
true
,
},
},
category
:{
type
:
String
,
}
},
{
},
{
timestamps
:
true
timestamps
:
true
})
})
export
default
mongoose
.
models
.
Place
||
mongoose
.
model
(
'
Place
'
,
PlaceSchema
)
export
default
mongoose
.
models
.
Place
s
||
mongoose
.
model
(
'
Place
'
,
PlaceSchema
)
server/scraperss.js
View file @
63b59e7d
...
@@ -3,9 +3,9 @@ import cheerio from "cheerio";
...
@@ -3,9 +3,9 @@ import cheerio from "cheerio";
import
express
from
'
express
'
;
import
express
from
'
express
'
;
import
request
from
'
request-promise
'
import
request
from
'
request-promise
'
import
jschardet
from
'
jschardet
'
import
jschardet
from
'
jschardet
'
import
iconv
from
'
iconv
'
//
import iconv from 'iconv'
import
fs
from
'
fs
'
//
import fs from 'fs'
const
Iconv
=
iconv
.
Iconv
//
const Iconv = iconv.Iconv
const
app
=
express
()
const
app
=
express
()
...
@@ -13,7 +13,7 @@ app.get('/', (req, res) => {
...
@@ -13,7 +13,7 @@ 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
"
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
)
request
(
url
)
.
then
(
anyToUtf8
)
//
.then(anyToUtf8)
.
then
((
html
)
=>
{
.
then
((
html
)
=>
{
// fs.writeFileSync("googlez.txt", '\ufeff' + html, { encoding: 'utf8' });
// fs.writeFileSync("googlez.txt", '\ufeff' + html, { encoding: 'utf8' });
...
...
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