DEV_희쨔응
Fluentd Web crawling 본문
현재 테스트 서버에 아래와 같은 데모시나리오 테스트/개발 을 완료 하였습니다.
네이버 API를 사용하여 Rockplace 관련 뉴스 기사 정보를 파이썬 코드로 Web crawling 한 후 JSON형식으로 변환 합니다 그 후 플루언트디의 HTTP 통신을 통해 Kafka Topic에 해당 Data를 적재합니다.
파이썬 예제 소스
import requests
import json
from bs4 import BeautifulSoup
from fluent import sender
sender.setup('myapp', host='10.65.41.142', port=8888)
url = 'https://openapi.naver.com/v1/search/news.json?'
clientid = "ERgXUWS4ipcN34mBCk2D"
clientsecret = "PISIoaGK2t"
queryString = "query=" + "락플레이스"
header = {
"X-Naver-Client-Id":clientid,
"X-Naver-Client-Secret":clientsecret
}
response = requests.get(url + queryString, headers=header)
soup = BeautifulSoup(response.content, 'html.parser')
data = response.json()
log = {'data': data, 'source': 'web'}
fluentd_url = 'http://10.65.41.142:8888/app.log'
req = requests.request('PUT','http://10.65.41.142:8888/test.cycle',json=log)
print(req.json)
플루언트디 예제 소스
<source>
@type http
port 8888
bind 0.0.0.0
</source>
<match app.log>
@type kafka2
brokers 10.65.41.147:9092
default_topic hogu_elastic2
<format>
@type json
</format>
<buffer fluentd-test>
@type memory
flush_interval 3s
overflow_action drop_oldest_chunk
</buffer>
</match>
Kafka Topic 데이터 확인
Comments