Commit 558b1436 authored by Lee SeoYeon's avatar Lee SeoYeon
Browse files

.

parents 3695b9ca 9168132d
...@@ -24,44 +24,30 @@ function App() { ...@@ -24,44 +24,30 @@ function App() {
setState(true); setState(true);
} }
return ( return (
<Container className="vh-100"> <Container className="vh-100 d-flex justify-content-md-center align-items-center">
<Row className="d-flex justify-content-md-center"> <Col md={6} lassName=" d-flex justify-content-center">
<Col md={6} className="mt-5"> <Row style={{marginBottom:20}}>
<Image src={ohuh} fluid /> <Image src={ohuh} />
</Col> </Row>
<Col md={9} className='mr-6'> <Row style={{marginBottom:500}}>
<Navbar bg="#fff" variant="light"> <Form className="vw-100" onSubmit={handleSubmit}>
<Nav className="mr-auto"> <InputGroup>
{user ? <Nav.Link onClick={() => handleLogout()}>로그아웃</Nav.Link> <Form.Control
: ( size="lg"
<> placeholder="검색어를 입력하세요."
<Nav.Link href="/signup">회원가입</Nav.Link> aria-label="Large"
<Nav.Link href="/login">로그인</Nav.Link> aria-describedby="inputGroup-sizing-sm"
</> onChange={handleChange}
)} />
</Nav> <InputGroup.Append>
</Navbar> <Button type='submit' variant="outline-secondary">검색</Button>
</Col> </InputGroup.Append>
<Col lg={{ span: 10, offset: 1 }} > </InputGroup>
<InputGroup size="lg" lg={6} xs={4} fluid> </Form>
<FormControl </Row>
className="d-flex justify-content-lg-center" </Col>
placeholder="검색어를 입력하세요."
aria-label="Large"
aria-describedby="inputGroup-sizing-sm"
onChange={handleChange}
/>
<InputGroup.Append>
<Button variant="outline-secondary" onClick={handleSubmit}>검색</Button>
</InputGroup.Append>
</InputGroup>
</Col>
</Row>
</Container> </Container>
); );
} }
......
...@@ -18,7 +18,6 @@ function Place(props) { ...@@ -18,7 +18,6 @@ function Place(props) {
getReview(); getReview();
}, []) }, [])
return ( return (
<Modal {...props} <Modal {...props}
size="xl" size="xl"
......
import Review from '../models/Review.js' import Review from '../models/Review.js'
import cheerio from "cheerio"; import cheerio from "cheerio";
import express from 'express';
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'
import axios from 'axios';
const Iconv = iconv.Iconv const Iconv = iconv.Iconv
const signup = async (req, res) => {
res.send("안녕하세요")
}
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
request(url) axios.get(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' });
let $ = cheerio.load(html, null, false); let $1 = cheerio.load(html.data);
let places = [] let reviews = []
$('.kCrYT').each(function (i) { $1('.kCrYT').each(function (i) {
const review = await Review.findOne({ link: $(this).find('a').attr('href') }) let link = ""
places[i] = { if ($1(this).find('a').attr('href')) {
title: $(this).find('h3').text(), link = ($1(this).find('a').attr('href')).match(editUrl)
link: $(this).find('a').attr('href'), }
summary: $(this).find('.s3v9rd').text(), reviews[i] = {
title: $1(this).find('h3').text(),
link: link,
summary: $1(this).find('.s3v9rd').text(),
} }
}) })
// 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(places) console.log(reviews)
res.send(places) res.send(reviews)
}) })
function anyToUtf8(str) { function anyToUtf8(str) {
const { encoding } = jschardet.detect(str); const { encoding } = jschardet.detect(str); // 웹페이지 문서의 인코딩 타입을 확인
console.log("source encoding = " + encoding); const iconv = new Iconv(encoding, "utf-8//translit//ignore"); // euc-kr 인코딩변환
const iconv = new Iconv(encoding, "utf-8//translit//ignore");
return iconv.convert(str).toString(); return iconv.convert(str).toString();
} }
// try { // try {
...@@ -48,6 +54,5 @@ const search = async (req, res) => { ...@@ -48,6 +54,5 @@ const search = async (req, res) => {
// } // }
} }
const
export default { signup, search } export default { search }
\ No newline at end of file \ No newline at end of file
...@@ -4,7 +4,6 @@ import review from '../controllers/review.controller.js' ...@@ -4,7 +4,6 @@ import review from '../controllers/review.controller.js'
const router = express.Router() const router = express.Router()
router.route('/api/review/:search') router.route('/api/review/:search')
.post(review.signup)
.get(review.search) .get(review.search)
export default router export default router
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment