Commit 0dfdacbe authored by baesangjune's avatar baesangjune
Browse files

.

parent 3515ba65
This diff is collapsed.
......@@ -19,6 +19,7 @@ function Place(props) {
getReview();
}, [])
return (
<Modal {...props}
size="xl"
......
......@@ -4,6 +4,7 @@ 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 axios from 'axios';
function Search(props) {
const endPage = 10;
......@@ -13,7 +14,25 @@ function Search(props) {
const [search, setSearch] = useState(props.location.state.id);
const [mobile, setMobile] = useState();
const [reviews, setReviews] = useState([])
const getReview = () => {
console.log('search', search)
axios.get(`/api/search/${search}`)
.then(res => {
console.log("res.data22222222=", res.data)
setReviews(res.data)
})
.catch(err => {
console.log('search.err발생',err)
})
}
useEffect(() => {
getReview()
if (window.innerWidth < 960) {
setMobile(true)
} else {
......@@ -21,6 +40,11 @@ function Search(props) {
}
}, []);
const places = [{
name: "한라산(hallasan)",
address: "제주 서귀포시 토평동 산15-1",
......
This diff is collapsed.
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')
}
}
import fs from 'fs'
import axios from 'axios';
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");
});
console.log("여기까지 도착합니다.@@@@@@@@@@@@@@@@@@@@@@@@@@@@@")
console.log(req.params.search)
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
axios.get(url)
.then((response) => {
const html = response.data
fs.writeFileSync("googlez.txt", html, { encoding: 'utf8' });
let $1 = cheerio.load(html);
let reviews = []
$1('.kCrYT').each(function (i) {
if ($1(this).find('h3').text()) {
reviews[i] = { name: $1(this).find('h3').text(), link: ($1(this).find('a').attr('href')) }
} else if ($1(this).find('.s3v9rd').find('.s3v9rd').text()) {
reviews[i - 1] = { ...reviews[i - 1], address: $1(this).find('.s3v9rd').find('.s3v9rd').text() }
reviews = reviews.filter(e => e)
}
})
// try {
// const newPlace = await new Place({
// name: req.params.search,
// address,
// img,
// })
// }
console.log("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",reviews)
res.send(reviews)
})
}
export default { signup, search }
export default { search }
import Review from '../models/Review.js'
import cheerio from "cheerio";
import jschardet from 'jschardet'
// import iconv from 'iconv'
import fs from 'fs'
import axios from 'axios';
// const Iconv = iconv.Iconv
const search = async (req, res) => {
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
axios.get(url)
// .then(anyToUtf8)
.then((response) => {
const html = response.data
fs.writeFileSync("googlez.txt", html, { encoding: 'utf8' });
......@@ -25,32 +22,10 @@ const search = async (req, res) => {
reviews = reviews.filter(e => e)
}
})
// 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("*******************************************",reviews)
res.send(reviews)
})
// function anyToUtf8(str) {
// const { encoding } = jschardet.detect(str); // 웹페이지 문서의 인코딩 타입을 확인
// const iconv = new Iconv(encoding, "utf-8//translit//ignore"); // euc-kr 인코딩변환
// return iconv.convert(str).toString();
// }
// try {
// const newPlace = await new Place({
// name: req.params.search,
// address,
// img,
// })
// }
}
......
......@@ -4,7 +4,6 @@ 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 express from 'express'
import connectDb from './utils/connectDb.js'
// import placeRouter from './routes/place.routes.js'
import placeRouter from './routes/place.routes.js'
import reviewRouter from './routes/review.routes.js'
connectDb()
......@@ -9,7 +9,7 @@ const app = express()
app.use(express.json())
// app.use(placeRouter)
app.use(placeRouter)
app.use(reviewRouter)
app.get('/', (req, res) => {
......
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