import requests
from bs4 import BeautifulSoup
response = requests.post(tranUrl, headers=headers, data=data, verify=False)
soup = BeautifulSoup(response.content,"html.parser")
print(soup.find(id="tw-answ-target-text").text)
return soup.find(id="tw-answ-target-text").text
verify=False 설정으로 SSL오류를 해결하고 나면 이번에는 아래와 같은 경고가 표시됩니다.
InsecureRequestWarning: Unverified HTTPS request is being made to host 'www.google.com'. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/advanced-usage.html#tls-warnings
warnings.warn(
인증서 검증으로 하라는 경고인데 아래와 같이 작성하며 경고를 숨길 수 있습니다.
import requests
from bs4 import BeautifulSoup
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # InsecureRequestWarning 경고를 무시하도록 설정
response = requests.post(tranUrl, headers=headers, data=data, verify=False)
soup = BeautifulSoup(response.content,"html.parser")
print(soup.find(id="tw-answ-target-text").text)
return soup.find(id="tw-answ-target-text").text
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning) # InsecureRequestWarning 경고를 무시하도록 설정
위 2개 코드를 추가하게 되면 해결됩니다.