일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | ||
6 | 7 | 8 | 9 | 10 | 11 | 12 |
13 | 14 | 15 | 16 | 17 | 18 | 19 |
20 | 21 | 22 | 23 | 24 | 25 | 26 |
27 | 28 | 29 | 30 | 31 |
- 모바일
- kafka
- 도커
- Materializations
- Java
- CDC
- 윈도우
- polars
- proerty
- freshness
- docker
- 카프카
- query history
- UI for kafka
- spring boot
- mysql
- DBT
- 쿠버네티스
- airflow
- 크롤링
- KubernetesPodOperator
- 동적 차트
- Python
- dbt_project
- ksql
- numpartitions
- k9s
- 파이썬
- bar cahrt
- spark
- Today
- Total
목록기타/crawler (6)
데이터 엔지니어 이것저것
크롤링이란 데이터를 수집하는 행위. 크롤링하는 프로그램을 크롤러 라고 합니다. 정확히는 scrapy와 구분해야하지만 편의상 crawler라고 하겠습니다. 대부분의 작업은 scrapy이고 상위 버전이 crawler 이다. scrapy는 일부분의 데이터만 가져와서 수집하는것이고 크롤러는 전체적인 데이터를 자동적으로 가져오는것이다.
스크래핑을 하다 보면 여러가지 이유로 인해 데이터가 누락되는 경우가 있다. 해당 데이터를 처리하는 방법은 많은데 나는 pipeline에서 처리할 예정이다. from scrapy.exceptions import DropItem if item['title']: # 만약 타이틀이 null, 못가져온다면 pass else: 1. item['title'] = 'Missing title' 2. raise DropItem("Missing title") # 해당 item 삭제 return item 이러한 로직으로 처리가 가능하다. if문을 통해 들어오는 item에 title이 빈값으로 들어올 경우 1. 해당 데이터를 default로 missig title이라고 지정을 해주거나 (저장 o) 2. DropItem을 하여 ..
class Pipeline: def open_spider(self, spider): hostname = 'localhost' username = 'postgres' password = '0000' database = 'postgres' self.connection = psycopg2.connect(host=hostname, user=username, password=password, dbname=database) self.cur = self.connection.cursor() def close_spider(self, spider): self.cur.close() self.connection.close() async def process_item(self, item, spider): self.cur.exe..
스크래피 관련 정보를 구글링해보면서 여러가지 page를 각기 다른 itme에 넣고 저장하는 하는 방법을 찾아보는데 원하는 방법을 찾지 못하여 직접 구현, 추후 더 좋은 방법을 찾게 되면 수정할 예정 1. A페이지에서 A item 수집 2. B페이지에서 B item 수집 3. C페이지에서 C item 수집 각각의 아이템을 명칭도 A,B,C class로 구현 class AItem(scrapy.Item): title = scrapy.Field() class BItem(scrapy.Item): title = scrapy.Field() class CItem(scrapy.Item): title = scrapy.Field() 이것들을 어떻게 구분하여 DataBase 또는 csv, json등의 파일을 구분하여 저장을 ..
# Obey robots.txt rules # robots.txt를 따를것인가 default = True ROBOTSTXT_OBEY = False #인코딩 FEED_EXPORT_ENCODING = 'utf-8' #default request header DEFAULT_REQUEST_HEADERS = { 'Referer': 'https://news.naver.com/' } #로그 출력 제거 LOG_ENABLED=False
스크래피는 웹 사이트를 크롤링하고 페이지에서 데이터를 추출하는데 사용되는 프레임워크이다. 공식문서 : https://docs.scrapy.org/en/latest/ Scrapy 2.5 documentation — Scrapy 2.5.0 documentation © Copyright 2008–2021, Scrapy developers. Revision 5fd75f86. Last updated on Apr 07, 2021. docs.scrapy.org pip install Scrapy scrapy startproject tutorial