Commit c8e037b0 authored by baesangjune's avatar baesangjune
Browse files

Merge remote-tracking branch 'origin/cherry' into Sangjune

parents 2ebe6356 b7e0b8ba
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
size="lg"
placeholder="검색어를 입력하세요." placeholder="검색어를 입력하세요."
aria-label="Large" aria-label="Large"
aria-describedby="inputGroup-sizing-sm" aria-describedby="inputGroup-sizing-sm"
onChange={handleChange} onChange={handleChange}
/> />
<InputGroup.Append> <InputGroup.Append>
<Button type='submit' variant="outline-secondary">검색</Button> <Button variant="outline-secondary" onClick={handleSubmit}>검색</Button>
</InputGroup.Append> </InputGroup.Append>
</InputGroup> </InputGroup>
</Form>
</Row>
</Col> </Col>
</Row>
</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 {
......
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 axios from "axios";
import cheerio from "cheerio"; import cheerio from "cheerio";
import express from 'express' import express from 'express';
import request from 'request' import request from 'request-promise'
import jschardet from 'jschardet'
import iconv from 'iconv'
import fs from 'fs'
const Iconv = iconv.Iconv
const app = express() const app = express()
// axios를 활용해 AJAX로 HTML 문서를 가져오는 함수 구현
// getHTML 함수 실행 후 데이터에서
// body > main > div > section > ul > li > article > h2 > a
// 에 속하는 제목을 titleList에 저장
app.get('/', (req, res) => { app.get('/', (req, res) => {
const url = "https://www.naver.com/" const url = "https://100mountain.tistory.com/117"
request(url, function (err, res, html) { request({
// console.log(html) url: url,
if (!err) { encoding: null,
let resultArr = []; })
.then(anyToUtf8)
let $ = cheerio.load(html, null, false); // false 넣으면 헤더같은 거 없애고 null은 속성넣어줄 수 있음. .then((html) => {
// fs.writeFileSync("test.txt", '\ufeff' + html, {encoding: 'utf8'});
let colArr = $(".list_theme_wrap")//가져올 클래스 넣기 let $ = cheerio.load(html, null, false);
for (let i = 0; i < colArr.length; i++) { let places = []
resultArr.push(colArr[i].children[1].attribs.title)
$('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();
} }
console.log(resultArr)
}
}
// .then(html => {
// let titleList = [];
// const $ = cheerio.load(html.data);
// // ul.list--posts를 찾고 그 children 노드를 bodyList에 저장
// const bodyList = $(".title_post > span");
// // bodyList를 순회하며 titleList에 h2 > a의 내용을 저장
// bodyList.each(function (i, elem) {
// titleList[i] = {
// title: $(this)
// .text()
// };
// });
// return titleList;
// })
// .then(res => console.log(res)); // 저장된 결과를 출력
)
}) })
app.listen(3001, () => { app.listen(3001, () => {
......
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