크롤링 11

크롤링_쇼핑몰 상품 데이터 수집

from selenium import webdriver as wb from selenium.webdriver.common.by import By # 키보드의 값을 보관하고 있는 라이브러리 from selenium.webdriver.common.keys import Keys from bs4 import BeautifulSoup as bs # 이미지 URL을 이용해서 파일로 저장시켜주는 라이브러리 from urllib.request import urlretrieve # 파일 시스템을 활용하기 위한 라이브러리 # 파일&폴더 생성, 삭제, 존재여부 확인 import os import time import pandas as pd # driver 객체 옵션 설정(GPU 사용X, 화면사이즈, 브라우저 숨김) opti..

크롤링 2022.07.01

크롤링_이미지 수집

# 폴더 존재 여부 확인하는 함수 def createDirectory(name): # True : 폴더 있음 / False : 폴더 없음 # 폴더를 확인하고 생성하는 함수 if not os.path.isdir(name): # 폴더생성 os.mkdir(name) dir_name = '최우식' # 폴더 생성 createDirectory(dir_name) imgUrl = 'https://blog.kakaocdn.net/dn/eegLhJ/btrlFnnyiDN/2KVyMuawSEoKuVAItmufnK/img.jpg' # urlretrieve(이미지경로, 폴더경로 or 파일명, 확장자) urlretrieve(imgUrl, f'./{dir_name}/최우식.jpg') # 1. 검색 결과 이미지 페이지를 driver ..

크롤링 2022.06.30

크롤링_유튜브 데이터 수집

from selenium import webdriver as wb from selenium.webdriver.common.by import By from bs4 import BeautifulSoup as bs import time import pandas as pd # f-string keyword = '강아지' yt_url = f'https://www.youtube.com/results?search_query={keyword}' driver = wb.Chrome() driver.get(yt_url) # selenium을 이용해서 HTML 문서를 변환한 후에는 반드시 브라우저를 종료해야 한다. html = bs(driver.page_source, 'lxml') driver.close() # seleniu..

크롤링 2022.06.30

크롤링_워드클라우드 그리기

# interplo plt.imshow(wc, interpolation = 'bilinear') plt.axis('off') Wordcloud 라이브러리 설치 # !pip install 설치할 라이브러리 이름 !pip install wordcloud # 워드클라우드를 그릴 때 사용하는 라이브러리 from wordcloud import WordCloud from collections import Counter import random import matplotlib.pyplot as plt # 원하는 색상을 RGB 값으로 저장 colors = [[255, 99, 72],[46, 213, 115],[83, 82, 237],[214, 48, 49],[232, 67, 147],[255, 118, 117]] # ..

크롤링 2022.06.30

크롤링_네이버 영화 리뷰 수집(실습)

url ='https://movie.naver.com/movie/bi/mi/pointWriteFormList.naver?code=81888&type=after&i[%E2%80%A6]geSubscriptionAlready=false&isMileageSubscriptionReject=false' # 서버에게 브라우저로 접속했다라는 것을 인지시키기 위한 헤더 header = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' } res = req.get(url, headers=header).text html = bs(res, 'lx..

크롤링 2022.06.28

크롤링_영화 이름 및 평점 수집(실습)

import requests as req import pandas as pd from bs4 import BeautifulSoup as bs # 아래 3개는 필수로 있어야 한다. url = 'https://movie.naver.com/movie/sdb/rank/rmovie.naver?sel=cur&date=20220627' header = { 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36' } res = req.get(url, headers=header).text html = bs(res, 'lxml') # 영화명과 평점을 수..

크롤링 2022.06.28

크롤링_멜론 음원 차트 수집(실습)

import requests as req import pandas as pd from bs4 import BeautifulSoup as bs url ='https://www.melon.com/chart/index.htm' # 서버에게 브라우저로 접속했다라는 것을 인지시키기 위한 헤더 header = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'} res = req.get(url, headers=header).text html = bs(res, 'lxml') # 하나만 가져오기 select_one # select를 이용하면 반..

크롤링 2022.06.27

크롤링_네이버 뉴스 데이터 수집(실습)

url ='https://n.news.naver.com/mnews/article/015/0004716773?sid=105' # 서버에게 브라우저로 접속했다라는 것을 인지시키기 위한 헤더 header = {'user-agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36'} res = req.get(url, headers=header).text html = bs(res, 'lxml') new_title = html.select_one('h2.media_end_head_headline') new_content = html.select_one('div#..

크롤링 2022.06.27

크롤링_beautifulSoup

beautifulSoup - HTML 문서를 파이썬 객체로 변환하여 원하는 정보는 가져올 때 사용하는 라이브러리 from bs4 import BeautifulSoup as bs # HTML 문서 -> 파이썬 객체로 변환 # 두번째 html = bs(res, 'lxml') print(type(html)) print(type(res)) # find(tag name): tag name으로 요소객체를 접근 html.find('title').text # 슬라이싱 html.find('title').text[:2] # 공백 없애기 html.find('title').text.replace(' ', ' ') html.find('a', {'class':'tit'}).text # div.product_info: a.titl..

크롤링 2022.06.27