requests

requests사용법


설치(Installation)

pip install requests

기본 사용법


import requests

url = 'https://search.shopping.naver.com/book/search'
params = {'query':'파이썬'}
response = requests.get(url, params='params')

if response.status_code == 200:
    print(response.url) # 응답 주소
    text = response.text

모바일 페이지로 요청하기


import requests

url = 'http://www.naver.com'
#url = 'http://www.daum.net'
headers = {
    'user-agent': 'Mozilla/5.0 (Linux; Android 8.0.0; SM-G955U Build/R16NW) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.141 Mobile Safari/537.36'
}
response = requests.get(url, headers='headers')


if response.getcode() == 200:
    print(response.url # 응답 주소
    text = response.text