본문 바로가기

파이썬 활용/크롤링

(9)
크로링 기초 _ 학교 수업 때 배운 부분 1. HTML¶ HTML: 웹 페이지의 구조를 나타내기 위한 언어이며 태그로 구성되어 있다. 태그 꺾쇠 괄호()로 표시하며 많은 대부분의 태그는 시작태그와 종료태그로 구성된다. 가장 큰 제목 두 번째로 큰 제목 태그는 속성명과 속성값이 올 수 있다. 가장 큰 제목 태그는 부모 태그와 자식 태그가 있다. 크롤링 시 자주 사용되는 태그 div: 구역 나누기 a: 링크 h1~h6: 제목 (h1의 글자 크기가 가장 크고, h6의 글자 크기가 가장 작다.) p: 문단 ul: 순서없는 목록 선언 li: 목록 2. 네이버 헤드라인 뉴스 크롤링¶ 목차 requests 라이브러리 beautifulsoup 라이브러리 네이버 헤드라인 뉴스 크롤링 2.1 requests 라이브러리¶ HTTP 통신을 위한 파이썬 라이브러..
API 크롤링_지역별 산불 통계 _ 학교 수업 때 배운 부분 In [ ]: In [34]: from google.colab import drive drive.mount('/gdrive', force_remount= True ) Mounted at /gdrive In [ ]: import requests as rq from bs4 import BeautifulSoup as bs import numpy as np import pandas as pd #2021년은 길이가 한부분 달라서 데이터 프레임 불가능 했더 site= 'https://apis.data.go.kr/1400000/forestStusService/getfirestatsservice?' userkey= 'serviceKey=AAAS9ZmuHQ8ul8jOsCMUTd%2BVwHzoVIN%2Fqa2GAqr78T..
크롤링한 데이터 엑셀에 저장 후 불러오기 크롤링 해서 엑셀파일로 저장¶ openpyxl 라이브 러리 사용¶ xlsx 파일읽고 저장 모두 가능 설치 터미널 모드에서 다음명령 실행 !pip install openpyxl In [2]: !pip install openpyxl Requirement already satisfied: openpyxl in c:\users\82105\anaconda3\lib\site-packages (3.0.9) Requirement already satisfied: et-xmlfile in c:\users\82105\anaconda3\lib\site-packages (from openpyxl) (1.1.0) In [8]: import openpyxl In [10]: excel_file = openpyxl.Workbook(..
네이버 api json 데이터 가져오기 In [1]: import json data = """ { "lastBuildDate": "Sat, 22 Jun 2019 14:57:13 +0900", "total": 634151, "start": 1, "display": 10, "items": [ { "title": "MHL 케이블 (아이폰, 안드로이드 스마트폰 HDMI TV연결)", "link": "https://search.shopping.naver.com/gate.nhn?id=10782444869", "image": "https://shopping-phinf.pstatic.net/main_1078244/10782444869.5.jpg", "lprice": "16500", "hprice": "0", "mallName": "투데이샵", "produc..
기상 데이터 크롤링(넘파이로 전처리) In [1]: import requests from bs4 import BeautifulSoup import pandas as pd In [2]: res = requests.get('https://www.weather.go.kr/w/obs-climate/land/city-obs.do') print(res) In [3]: soup=BeautifulSoup(res.content, 'html.parser') soup Out[3]: 메인메뉴 바로가기 본문 바로가기 기상청 날씨누리 홈 바로가기 KOR ENG CHN JPN 날씨 기상특보 특보현황 통보문 영향예보 가뭄예보 안개정보 기상특보 발표기준 국민행동요령 날씨상황판 예보 단기예보 중기예보 북한날씨 장기전망 1개월 전망 3개월 전망 3개월 전망 해설서 기후감시요..
지마켓 탑100개 (품명 ,가격) 크롤링 + 엑셀에 저장 Crawling & Crawing¶ 1. 실전 예제: 크롤링¶ 이커머스(지마켓) 베스트100 상품 타이틀/가격 추출하기 In [2]: import requests from bs4 import BeautifulSoup import re res = requests.get('http://corners.gmarket.co.kr/Bestsellers?viewType=G&groupCode=G06') soup = BeautifulSoup(res.content, 'html.parser') bestlists = soup.select('div.best-list') bestitems = bestlists[0] products = bestitems.select('ul li') for index, product in enume..
크롤링 지마켓- 상품명 + 배송사 크롤링 지마켓 베스트 페이지 상품명 가격 + 이중 크로링으로 배송사 알아내기¶ In [1]: import requests from bs4 import BeautifulSoup import re res = requests.get('http://corners.gmarket.co.kr/Bestsellers?viewType=G&groupCode=G06') soup = BeautifulSoup(res.content, 'html.parser') bestlists = soup.select('div.best-list') bestitems=bestlists[0] #혹시 html에 동일한 div가 있을수도 있기때문에 몀ㅊ번째 div인지 지정 bestitem = bestitems.select('ul > li') for index,..
다중 크롤링 네이버 쇼핑몰, 주식 네이버쇼핑몰 크롤링¶ 상품명 크롤링후 상품명 문장 전처리¶ In [18]: import requests from bs4 import BeautifulSoup res = requests.get('https://davelee-fun.github.io/') soup = BeautifulSoup(res.content, 'html.parser') items = soup.select('div.card-body > h4') for index,item in enumerate(items): print (str(index+1),item.get_text().split(':')[1].split(',')[0].strip()) 1 보몽드 순면스퀘어 솔리드 누빔매트커버 2 슈에뜨룸 선인장 리플 침구 세트 3 선우랜드 레인보우 2단..