해결된 질문
작성
·
502
·
수정됨
0
쿠팡 1강따라서 실행했는데 이렇게 에러가 나는데요. 어떻게 해야 할까요?
import requests from bs4 import BeautifulSoup
base_url = "https://www.coupang.com/np/search?component=&q="
keyword = input('검색할 상품을 입력하세요:')
search_url = base_url + keyword print(search_url)
headers = {'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36'}
cookie = {"a": "b"} req = requests.get(search_url, timeout=5, headers=headers, cookies=cookie)
print(req.status_code)
결과:
검색할 상품을 입력하세요:모니터
https:https://www.coupang.com/np/search?component=&q=모니터
Traceback (most recent call last):
File "d:\main3.py", line 17, in <module>
req = requests.get(search_url, timeout=5, headers=headers, cookies=cookie)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
답변 1
0
headers에 "User-Agent" 이부분이 빠졌습니다.
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/110.0.0.0 Safari/537.36"
이렇게 넣고 다시 한번 해보세요.