Skip to content

Instantly share code, notes, and snippets.

@allieus
Last active December 3, 2018 06:23
Show Gist options
  • Save allieus/2a083babf5a24bc10e7f5c9877473af5 to your computer and use it in GitHub Desktop.
Save allieus/2a083babf5a24bc10e7f5c9877473af5 to your computer and use it in GitHub Desktop.
교보문고 검색결과 크롤링 by Ask Company

keyword_encode 로직은 교보문고 페이지의 javascript 로직을 그대로 흉내내어 만들었습니다.

실행결과

>>> search('파이썬')

Do it! 점프 투 파이썬
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9788997390915&orderClick=LAG&Kc=
케라스 창시자에게 배우는 딥러닝(Deep Learning with Python)
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791160505979&orderClick=LAG&Kc=
모두의 파이썬
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791160505856&orderClick=LAG&Kc=
파이썬으로 데이터 주무르기
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791186697474&orderClick=LAG&Kc=
파이썬 라이브러리를 활용한 머신러닝
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9788968483394&orderClick=LAG&Kc=
Effective Python 파이썬 코딩의 기술
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791186978825&orderClick=LAG&Kc=
파이썬 웹 프로그래밍
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791162241042&orderClick=LAG&Kc=
파이썬 데이터 분석 입문
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791162240144&orderClick=LAG&Kc=
파이썬 코딩 도장
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791160506181&orderClick=LAG&Kc=
데이터 분석을 위한 파이썬 철저 입문
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791158391126&orderClick=LAG&Kc=
파이썬 GUI 프로그래밍 쿡북 2/e
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791161751474&orderClick=LAG&Kc=
파이썬 자연어 처리의 이론과 실제
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791161751726&orderClick=LAG&Kc=
파이썬 라이브러리를 활용한 데이터 분석
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9788968480478&orderClick=LAG&Kc=
파이썬을 이용한 머신러닝  딥러닝 실전 개발 입문
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791158390679&orderClick=LAG&Kc=
초보자를 위한 파이썬(Python) 200제
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9788956747347&orderClick=LAG&Kc=
Python Machine Learning By Example
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791161752037&orderClick=LAG&Kc=
내꺼하자! 파이썬! 왕초보! 파이썬 배워 크롤러 DIY 하다!
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791195484720&orderClick=LAG&Kc=
처음 시작하는 파이썬
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9788968482397&orderClick=LAG&Kc=
파이썬 데이터 사이언스 핸드북
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791158390730&orderClick=LAG&Kc=
파이썬으로 배우는 머신러닝의 교과서
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791162241240&orderClick=LAG&Kc=
Python Machine Learning By Example
http://www.kyobobook.co.kr/product/detailViewKor.laf?ejkGb=KOR&mallGb=KOR&barcode=9791161752037&orderClick=LIS&Kc=

by Ask Company

import requests
from bs4 import BeautifulSoup
from urllib.parse import quote, urljoin
def keyword_encode(s):
encoded = ''
for ch in s:
code = ord(ch)
if code > 127:
encoded += '&#' + str(code) + ';'
else:
encoded += str(code)
return encoded
def search(keyword):
data = {
'vPstrKeyWord': keyword_encode(keyword),
'vPstrCategory': 'TOT',
'vPplace': 'top',
'searchKeyword': quote(keyword.encode('euckr')),
}
search_url = "http://www.kyobobook.co.kr/search/SearchCommonMain.jsp"
res = requests.post(search_url, data=data)
soup = BeautifulSoup(res.text, 'html.parser')
for tag in soup.select('.title a'):
detail_url = tag['href']
if 'detailViewKor' in detail_url:
detail_url = urljoin(search_url, detail_url)
title = tag.select_one('strong').text.strip()
print(title)
print(detail_url)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment