상세 컨텐츠

본문 제목

[파이썬 웹 스크래핑] User Agent

프로그래밍 언어/웹 스크래핑

by 별을 보는 사람 2020. 8. 28. 07:00

본문

반응형
import requests
url = "http://danny610.tistory.com"
# User-Agent 정보 : https://www.whatismybrowser.com/detect/what-is-my-user-agent
headers = {"User-Agent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.135 Safari/537.36"}
res = requests.get(url, headers=headers)
res.raise_for_status()
with open("mygoogle.html", "w", encoding="utf8") as f:
    f.write(res.text)
반응형

관련글 더보기

댓글 영역