brunch

You can make anything
by writing

C.S.Lewis

by 무명 Sep 05. 2017

ip변경, user-agent 변조를 통한 크롤링

python, beautiful soup, fake_useragent

[상황]

맥북에서 python-beautiful soup으로 google scholar를 크롤링하던 와중 ip 차단으로 인해 크롤링 불가 


[해결책]

1. ip 변경 

- 아래와 같이 3G 세팅을 하고 

- 편하게 아이폰-맥북 usb연결로 핫스팟을 킴.

https://support.apple.com/ko-kr/HT203124

http://www.netmanias.com/ko/?m=view&id=techdocs&no=10471


- 혹은, lte에서 에어플레인 모드 on/off로 아이피 갱신 


2. fake user agent 사용 


ua = UserAgent()

ua.random

과 같은 식으로 사용 가능하다. 


headers = {'User-Agent':str(ua.random)}

으로 requests.get 시에 headers 삽입 


-user agent 

https://en.wikipedia.org/wiki/User_agent


- fake-useragent 0.1.7

https://pypi.python.org/pypi/fake-useragent


- fake_useragent

https://stackoverflow.com/questions/27652543/how-to-use-python-requests-to-fake-a-browser-visit


3. sleep

time.sleep()

으로 불규칙한 동작 수행 


작가의 이전글 일요일 스터디 03
작품 선택
키워드 선택 0 / 3 0
댓글여부
afliean
브런치는 최신 브라우저에 최적화 되어있습니다. IE chrome safari