파이썬3 웹 크롤링 HTTP error 403 발생시 해결방법
안녕하세요?
오늘은 그동안 잘 되던 웹크롤링에서 http error 403 이 발생하여 해결한 내용 기록하겠습니다.
에러가 발생한 이유는 mod_security 또는 다른 비슷한 서버 시큐리티가 알려진 사용자 봇을 블록 시키기 때문이라고 합니다.
가이드에 따라,
브라우저 유저 에이전트를 시도해 보았습니다.
수정전>
from urllib.request import Request, urlopen urlTicker = urllib.request.urlopen('https://api.bithumb.com/public/ticker/%s_KRW' % ticker) |
<수정후>
from urllib.request import Request, urlopen urlTicker = Request('https://api.bithumb.com/public/ticker/%s_KRW' % ticker, headers={'User-Agent': 'Mozilla/5.0'}) readTicker = urlopen(urlTicker).read() jsonTicker = json.loads(readTicker) |
오~ 역시, 깔끔하게 해결이 되었습니다.
다음 블러그를 참조하여 작성하였습니다. 도움에 감사드립니다.
파이썬3 웹 크롤링 HTTP error 403이 뜰 때 해결하는 방법
파이썬3에서 urllib.request를 사용할 때 HTTP Error 403이 뜰 때 해결하는 방법다음과 같은 코드를...
blog.naver.com
https://stackoverflow.com/questions/16627227/http-error-403-in-python-3-web-scraping
HTTP error 403 in Python 3 Web Scraping
I was trying to scrap a website for practice, but I kept on getting the HTTP Error 403 (does it think I'm a bot)? Here is my code: #import requests import urllib.request from bs4 import Beautiful...
stackoverflow.com