Toggle navigation
Toggle navigation
This project
Loading...
Sign in
bluejoyq
/
searchGuide
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Snippets
Network
Create a new issue
Builds
Commits
Issue Boards
Authored by
김서영
2019-12-05 01:53:17 +0900
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
4675a06007e308323b3bcc7d418e71753a49f522
4675a060
1 parent
105387ca
add search.js search browser
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
2 deletions
api/search.js
api/search.js
View file @
4675a06
...
...
@@ -5,6 +5,11 @@ const machineRead = require('./machineRead');
const
entities
=
new
Entities
();
const
searchURL
=
{
"naver"
:
"https://search.naver.com/search.naver?"
,
"google"
:
"https://www.google.com/search?"
}
const
keywordChecking
=
(
keywordText
,
$
,
elem
)
=>
{
let
tempCheck
=
false
;
keywordText
.
split
(
' '
).
forEach
(
(
Word
)
=>
{
...
...
@@ -19,6 +24,20 @@ const keywordChecking = ( keywordText, $, elem ) => {
return
false
;
}
const
google
=
(
searchResult
,
$
,
elem
,
defaultURL
)
=>
{
searchResult
.
passage
=
entities
.
decode
(
$
(
elem
).
parent
().
parent
().
parent
().
text
()).
trim
(),
searchResult
.
url
=
decodeURIComponent
(
$
(
elem
).
attr
(
"href"
)
);
searchResult
.
title
=
entities
.
decode
(
$
(
elem
).
children
(
"div"
).
text
()
);
// title 캐오기 수정 가능
if
(
searchResult
.
url
.
indexOf
(
"/url?q="
)
===
0
)
{
searchResult
.
url
=
searchResult
.
url
.
replace
(
"/url?q="
,
""
);
}
else
if
(
searchResult
.
url
.
indexOf
(
"/search?"
)
===
0
)
{
searchResult
.
url
=
"https://google.com"
+
searchResult
.
url
;
}
else
{
searchResult
.
url
=
defaultURL
;
}
}
const
naver
=
(
searchResult
,
$
,
elem
,
defaultURL
)
=>
{
searchResult
.
title
=
$
(
elem
).
parent
().
attr
(
"title"
);
searchResult
.
passage
=
entities
.
decode
(
$
(
elem
).
parent
().
parent
().
parent
().
text
()).
trim
(),
...
...
@@ -44,6 +63,7 @@ const searchToResult = (searchResult, result, keywordCheck) => {
result
.
push
(
searchResult
);
}
}
else
if
(
keywordCheck
)
{
}}
const
getHtmlMain
=
(
main
,
keywordText
,
html
,
defaultURL
,
findSearchResult
)
=>
{
...
...
@@ -66,7 +86,7 @@ search.naver = ( keywordText ) => {
return
new
Promise
(
async
(
resolve
,
reject
)
=>
{
let
naverMain
=
"#main_pack strong"
,
result
=
[],
naverURL
=
"https://search.naver.com/search.naver?
query="
+
encodeURI
(
keywordText
);
naverURL
=
searchURL
.
naver
+
"
query="
+
encodeURI
(
keywordText
);
rp
(
{
"uri"
:
naverURL
,
}
)
...
...
@@ -77,5 +97,20 @@ search.naver = ( keywordText ) => {
})
}
search
.
google
=
(
keywordText
)
=>
{
return
new
Promise
(
(
resolve
,
reject
)
=>
{
let
googleMain
=
"#main a"
,
result
=
[],
googleURL
=
searchURL
.
google
+
"q="
+
encodeURI
(
keywordText
)
rp
(
{
"uri"
:
googleURL
,
})
.
then
(
(
html
)
=>
{
result
=
getHtmlMain
(
googleMain
,
keywordText
,
html
,
googleURL
,
google
);
resolve
(
result
);
})
})
}
module
.
exports
=
search
\ No newline at end of file
module
.
exports
=
search
;
\ No newline at end of file
...
...
Please
register
or
login
to post a comment