데이터 분석 시각화 total 정리
·
과거 기록들/Data Analysis
그래프 그리기 import pandas as pd import numpy as np import matplotlib.pyplot as plt import seaborn as sns from sklearn.preprocessing import MinMaxScaler, StandardScaler import warnings warnings.filterwarnings( 'ignore' ) plt.plot([1, 0, 5, 2, 3]) plt.show() dict1 = {'v1' : [1, 2, 3, 4, 5], 'v2' : [8, 7, 6, 5, 4]} plt.plot('v1', 'v2', data = dict1) plt.show() # dictionary 형태로 그래프그리기 dict1 = {'x':[1,2,..
008 Scrapy 실습
·
과거 기록들/Web Crawling
scrapy - 비동기 방식으로 데이터를 수집 > 데이터 수집 속도가 빠름 import scrapy, requests from scrapy.http import TextResponse # Gmarket 베스트 200 상품 데이터 수집 # 1. 스크레피 프로젝트 생성 !scrapy startproject gmarket !tree gmarket /f items.py : 수집할 데이터의 구조 정의 middlewares.py : 데이터를 수집할때 headers 정보와 같은 내용을 설정 pipelines.py : 데이터를 수집한 후에 코드 실행 정의 settings.py : 크롤링 설정 : 크롤링 시간 텀, robots.txt 규칙 spiders : 디렉토리 : 크롤링 절차 정의 # 2. xpath 찾기 : 링크..
007-1 실습, xpath 사용
·
과거 기록들/Web Crawling
xpath - html element 선택하는 방법 - scrapy 에서 기본적으로 사용하는 selector - scrapy : 파이썬 코드로 웹페이지의 데이터를 수집하는 프레임워크 # !pip install scrapy import scrapy, requests from scrapy.http import TextResponse # 네이버 연관검색어 수집 query = "kt" url = f"https://search.naver.com/search.naver?query={query}" response = requests.get(url) dom = TextResponse(response.url, body=response.text, encoding="utf-8") xpath syntax // | * | [@..
006-2 실습, Selenium (네이버 중고나라 게시글 데이터 수집)
·
과거 기록들/Web Crawling
네이버 중고나라 게시글 데이터 수집 - selenium에서 iframe에 있는 데이터 수집 - https://cafe.naver.com/joonggonara.cafe 중고나라 : 네이버 카페 1초에 평균 4.5건의 신상품 등록! 찾는 그 제품, 중고나라에는 다 있다! cafe.naver.com from selenium import webdriver from selenium.webdriver.common.by import By import pandas as pd url = "https://cafe.naver.com/joonggonara.cafe" # url 설정 # 1. 웹브라우져 열기 및 페이지 이동 driver = webdriver.Chrome() driver.get(url) # 2. 검색창에 "맥북"..
006-1 실습, Selenium (TED 데이터 수집)
·
과거 기록들/Web Crawling
selenium - `https://www.selenium.dev` - 자동화를 목적으로 만들어진 다양한 브라우져와 언어를 지원하는 라이브러리 - 크롬 브라우져 설치 - 크롬 브라우져 드라이버 다운로드 (크롬 브라우져와 같은 버전) - 다운로드한 드라이버 압축 해제 - chromedriver, chromedriver.exe 생성 - windows : 주피터 노트북 파일과 동일한 디렉토리에 chromedriver.exe 파일 업로드 - mac : sudo cp ~/Download/chromedirver /usr/local/bin # install selenium # !pip install selenium 다루는법 기본 import pandas as pd from selenium import webdrive..
006-1 실습, Gmarket 상품 데이터 수집 (+ 이미지)
·
과거 기록들/Web Crawling
Gmarket - 베스트 상품 200개 데이터 수집 - 상품의 이미지 200개 다운로드 import pandas as pd import requests from bs4 import BeautifulSoup import os # 폴더 생성에 사용 from PIL import Image as pil # 이미지 확인에 사용 # 1. URL 찾기 url = "http://corners.gmarket.co.kr/Bestsellers" # 2. request > response : str(html) response = requests.get(url) print(response) # 3. bs > DataFrame dom = BeautifulSoup(response.text, "html.parser") # selec..
005-1 실습, 네이버 연관 검색어 수집
·
과거 기록들/Web Crawling
네이버 연관 검색어 수집 - 정적(static) 웹페이지 데이터 수집 - BeautifulSoup을 이용하여 HTML 문자열 데이터 parsing import pandas as pd import requests from bs4 import BeautifulSoup from datetime import datetime # 1. 웹페이지 분석 : URL query = "삼성전자" url = f"https://search.naver.com/search.naver?query={query}" print(url) # 2. request(URL) > response : str(html) response = requests.get(url) print(response) print(response.text[:250]) #..
005-0 개념, CSS Selector
·
과거 기록들/Web Crawling
CSS Selector CSS 셀렉터는 CSS 스타일을 적용시킬 HTML 엘리먼트를 찾기 위한 방법 입니다. 1. Element Selector 엘리먼트를 이용하여 선택할때 사용 css selector로 div를 사용하면 가장 위에 있는 dss1이 선택 dss1 dss2 dss3 2. ID Selector 아이디를 이용하여 선택할때 사용 아이디를 셀렉할때는 #(아이디 이름)으로 선택 css selector로 #ds2를 사용하면 dss2가 선택 여러개를 셀렉할때는 ,로 구분 css selector로 #ds2, #ds3를 사용하면 dss2와 dss3가 선택 dss1 dss2 dss3 3. Class Selector 클래스를 이용하여 선택할때 사용 클래스를 셀렉할때는 .(클래스 이름)으로 선택 엘리멘트를 그룹..