Commit b7e0b8ba authored by Kim, Chaerin's avatar Kim, Chaerin
Browse files

?

parent f9bcb8f6
This diff is collapsed.
import React, { useEffect, useState } from 'react'; import React, { useEffect, useState } from 'react';
import { Link, Redirect } from 'react-router-dom'; import { Link, Redirect } from 'react-router-dom';
import ohuh from './ohuh.PNG'; import ohuh from '../ohuh.PNG';
import { Container, Row, Form, Image, InputGroup, Button, Col } from 'react-bootstrap'; import { Container, Row, Form, Image, InputGroup, Button, Col, FormControl } from 'react-bootstrap';
function App() { function App() {
const [state, setState] = useState(false); const [state, setState] = useState(false);
...@@ -25,31 +25,28 @@ function App() { ...@@ -25,31 +25,28 @@ function App() {
return ( return (
<Container className="vh-100 d-flex justify-content-md-center align-items-center"> <Container className="vh-100">
<Col md={6} lassName=" d-flex justify-content-center"> <Row className="d-flex justify-content-md-center">
<Row style={{marginBottom:20}}> <Col md={6} className="mt-5">
<Image src={ohuh} /> <Image src={ohuh} fluid />
</Row> </Col>
<Col lg={{ span: 10, offset: 1 }} >
<Row style={{marginBottom:500}}> <InputGroup size="lg" lg={6} xs={4} fluid>
<Form className="vw-100" onSubmit={handleSubmit}> <FormControl
<InputGroup> className="d-flex justify-content-lg-center"
<Form.Control placeholder="검색어를 입력하세요."
size="lg" aria-label="Large"
placeholder="검색어를 입력하세요." aria-describedby="inputGroup-sizing-sm"
aria-label="Large" onChange={handleChange}
aria-describedby="inputGroup-sizing-sm" />
onChange={handleChange} <InputGroup.Append>
/> <Button variant="outline-secondary" onClick={handleSubmit}>검색</Button>
<InputGroup.Append> </InputGroup.Append>
<Button type='submit' variant="outline-secondary">검색</Button> </InputGroup>
</InputGroup.Append> </Col>
</InputGroup> </Row>
</Form>
</Row>
</Col>
</Container> </Container>
); );
} }
......
import React, { useState, useEffect } from 'react'; import React, { useState, useEffect } from 'react';
import { Link, Redirect } from 'react-router-dom'; import { Link, Redirect } from 'react-router-dom';
import ohuh from './ohuh-sm.PNG'; 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';
function Search(props) { function Search(props) {
const endPage = 10; const endPage = 10;
......
...@@ -2,8 +2,8 @@ import React from 'react'; ...@@ -2,8 +2,8 @@ import React from 'react';
import ReactDOM from 'react-dom'; import ReactDOM from 'react-dom';
import './index.css'; import './index.css';
import 'bootstrap/dist/css/bootstrap.min.css'; import 'bootstrap/dist/css/bootstrap.min.css';
import App from './App'; import App from './Pages/App';
import Search from './Search'; import Search from './Pages/Search';
import axios from 'axios'; import axios from 'axios';
import reportWebVitals from './reportWebVitals'; import reportWebVitals from './reportWebVitals';
import { import {
......
...@@ -5,6 +5,7 @@ ...@@ -5,6 +5,7 @@
"main": "index.js", "main": "index.js",
"type": "module", "type": "module",
"scripts": { "scripts": {
"dev": "nodemon server/server.js",
"test": "echo \"Error: no test specified\" && exit 1" "test": "echo \"Error: no test specified\" && exit 1"
}, },
"repository": { "repository": {
......
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
...@@ -12,25 +12,31 @@ const signup = async (req, res) => { ...@@ -12,25 +12,31 @@ const signup = async (req, res) => {
} }
const search = async (req, res) => { const search = async (req, res) => {
console.log(req.params.search) const url = "https://www.google.com/search?q=" + encodeURI(req.params.search) + "+site%3Atistory.com" + '&page_no=1'
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"
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' });
let $ = cheerio.load(html, null, false); let $ = cheerio.load(html, null, false);
let places = [] let places = []
$('.kCrYT').each(function (i) { $('.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] = { places[i] = {
title: $(this).find('h3').text(), title: $(this).find('h3').text(),
link: $(this).find('a').attr('href'), link: $(this).find('a').attr('href'),
summary: $(this).find('.s3v9rd ').text(), summary: $(this).find('.s3v9rd').text(),
} }
}) })
// console.log(places)
// console.log(places)
res.send(places) res.send(places)
}) })
function anyToUtf8(str) { function anyToUtf8(str) {
...@@ -39,8 +45,6 @@ const search = async (req, res) => { ...@@ -39,8 +45,6 @@ const search = async (req, res) => {
const iconv = new Iconv(encoding, "utf-8//translit//ignore"); const iconv = new Iconv(encoding, "utf-8//translit//ignore");
return iconv.convert(str).toString(); return iconv.convert(str).toString();
} }
// try { // try {
// const newPlace = await new Place({ // const newPlace = await new Place({
// name: req.params.search, // name: req.params.search,
...@@ -51,4 +55,6 @@ const search = async (req, res) => { ...@@ -51,4 +55,6 @@ const search = async (req, res) => {
// } // }
} }
const
export default { signup, search } export default { signup, search }
\ No newline at end of file
...@@ -3,14 +3,17 @@ import mongoose from 'mongoose' ...@@ -3,14 +3,17 @@ import mongoose from 'mongoose'
const { String } = mongoose.Schema.Types const { String } = mongoose.Schema.Types
const ReviewSchema = new mongoose.Schema({ const ReviewSchema = new mongoose.Schema({
title: {
type: String,
},
link: { link: {
type: String, type: String,
required: true, required: true,
unique: true,
}, },
content: { summary: {
type: String, type: String,
required: true, required: true,
unique: true,
}, },
keyword: { keyword: {
type: Array, type: Array,
......
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
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
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
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