puppeteer 사용하여 크롤링해보기
MySQL공부하기(5주차까지 다들어보기)
소켓 공부 자료 https://poiemaweb.com/nodejs-socketio
Node.js 크롤링 개념 자료 https://bluayer.com/35
Node.js 크롤링 실전예제 자료! https://velog.io/@jinuku/Puppeteer를-이용한-웹-크롤링-해보기-예제-1
kakao 소셜로그인 https://velog.io/@nara7875/Node.js-kakao-login-api-가져오기
google 소셜 로그인https://uju-tech.tistory.com/entry/Nodejs-소셜로그인-정복하기-google
채팅봇 https://dev-dain.tistory.com/71
Node.js 크롤링
//먼저는 npm init -y package.json 설치한다.
//그리고 npm i puppeteeer 을 설치해준다.
const puppeteer = require('puppeteer')
const cherrio = require('cherrio')
(async()=> {
//브라우저를 실행한다.
//옵션으로 headless 모드를 끌 수 있다.
const browser = await puppeteer.launch({
// true 는 인터넷 창을 열지않겠다!
// false 는 인터넷 창을 열겠다!
headless = false
})
//새로운 페이지를 연다
//페이지의 크기를 설정한다.
await page.setViewport({
width:1366,
height:768
})
//야놀자 사이트...ㅎㅎ
//goto안에는 크롤링 하고자하는 사이트URL 입력
await page.goto("https://www.goodchoice.kr/product/search/2")
//페이지의 HTML을 가져온다.
const content = await page.content()
//$에 cheerio를 로드한다.
const $ = cheerio.load(content)
//복사한 리스트의 Selector로 리스트를 모두 가져온다.
//#product_list_area > li:nth-child(2)
const lists = $("#product_list_area > li")
//모든 리스트를 순회한다.
lists.each((index,list)=> {
//호텔의 이름을 가져온다.
//#poduct_list_area > li:nth-child(2) > a > div > div.name > strong
const name = $(list).find('a > div > div.name > strong').text()
//호텔의 가격을 가져온다.
// #poduct_list_area > li:nth-child(2) > a > div > div.price > p > b
const price = $(list).find('a > div > div.price > p > b').text()
//호텔의 위치를 가져온다.
// #poduct_list_area > li:nth-child(2) > a > div > div.name > p:nth-child(4)
const location = $(list).find('a > div > div.name > p:nth-child(4)').text().slice(25,43)
console.log({
index,name,price,location
})
})
browser.close()
})()
MySQL
Select 쿼리문의 개념
쿼리(Query)문이란? 쿼리는 질의를 의미합니다.
즉 데이터베이스에 명령을 내리는 것을 의미합니다.
여기서 Select 쿼리문은, 데이터베이스에서 ‘데이터를 선택해서 가져오겠다’는 의미입니다.
테이블과 필드는 뭘까요??
예시) Select 쿼리문을 통해 'orders 테이블의 created_at, course_title, payment_method, email 필드를 가져와줘!'라고 명령을 내릴 수 있답니다.