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 { Link, Redirect } from 'react-router-dom';
import ohuh from './ohuh.PNG';
import { Container, Row, Form, Image, InputGroup, Button, Col } from 'react-bootstrap';
import ohuh from '../ohuh.PNG';
import { Container, Row, Form, Image, InputGroup, Button, Col, FormControl } from 'react-bootstrap';
function App() {
const [state, setState] = useState(false);
......@@ -25,31 +25,28 @@ function App() {
return (
<Container className="vh-100 d-flex justify-content-md-center align-items-center">
<Col md={6} lassName=" d-flex justify-content-center">
<Row style={{marginBottom:20}}>
<Image src={ohuh} />
</Row>
<Row style={{marginBottom:500}}>
<Form className="vw-100" onSubmit={handleSubmit}>
<InputGroup>
<Form.Control
size="lg"
placeholder="검색어를 입력하세요."
aria-label="Large"
aria-describedby="inputGroup-sizing-sm"
onChange={handleChange}
/>
<InputGroup.Append>
<Button type='submit' variant="outline-secondary">검색</Button>
</InputGroup.Append>
</InputGroup>
</Form>
</Row>
</Col>
<Container className="vh-100">
<Row className="d-flex justify-content-md-center">
<Col md={6} className="mt-5">
<Image src={ohuh} fluid />
</Col>
<Col lg={{ span: 10, offset: 1 }} >
<InputGroup size="lg" lg={6} xs={4} fluid>
<FormControl
className="d-flex justify-content-lg-center"
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>
);
}
......
import React, { useState, useEffect } from 'react';
import { Link, Redirect } from 'react-router-dom';
import ohuh from './ohuh-sm.PNG';
import Place from './Components/Place';
import ohuh from '../ohuh-sm.PNG';
import Place from '../Components/Place';
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) {
const endPage = 10;
......
......@@ -2,8 +2,8 @@ import React from 'react';
import ReactDOM from 'react-dom';
import './index.css';
import 'bootstrap/dist/css/bootstrap.min.css';
import App from './App';
import Search from './Search';
import App from './Pages/App';
import Search from './Pages/Search';
import axios from 'axios';
import reportWebVitals from './reportWebVitals';
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 express from 'express'
import request from 'request'
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()
// axios를 활용해 AJAX로 HTML 문서를 가져오는 함수 구현
// getHTML 함수 실행 후 데이터에서
// body > main > div > section > ul > li > article > h2 > a
// 에 속하는 제목을 titleList에 저장
app.get('/', (req, res) => {
const url = "https://www.naver.com/"
request(url, function (err, res, html) {
// console.log(html)
if (!err) {
let resultArr = [];
let $ = cheerio.load(html, null, false); // false 넣으면 헤더같은 거 없애고 null은 속성넣어줄 수 있음.
let colArr = $(".list_theme_wrap")//가져올 클래스 넣기
for (let i = 0; i < colArr.length; i++) {
resultArr.push(colArr[i].children[1].attribs.title)
}
console.log(resultArr)
}
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();
}
// .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, () => {
......
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