In [2]:
import requests
url = 'https://news.v.daum.net/v/20190728165812603'
In [1]:
resp = requests.get(url)
# resp.text
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
c:\Repository\StudyPython_2022_intermediate\WebCrawling\Practice.ipynb Cell 2' in <cell line: 1>()
----> <a href='vscode-notebook-cell:/c%3A/Repository/StudyPython_2022_intermediate/WebCrawling/Practice.ipynb#ch0000005?line=0'>1</a> resp = requests.get(url)

NameError: name 'requests' is not defined
In [ ]:
url = 'https://news.v.daum.net/v/20190728165812603'
headers = {
    "user-agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/102.0.0.0 Safari/537.36"
}
resp = requests.get(url, headers=headers)
# resp.text
In [7]:
url = 'https://news.v.daum.net/v/20190728165812603'
resp = requests.get(url)
type(resp)
Out[7]:
requests.models.Response
In [10]:
resp.status_code
Out[10]:
200
In [9]:
if resp.status_code == 200:
    print(resp.headers)
else:
    print('error!!!')
{'Date': 'Sat, 11 Jun 2022 16:41:58 GMT', 'Content-Type': 'text/html;charset=UTF-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'content-encoding': 'gzip', 'Strict-Transport-Security': 'max-age=15724800; includeSubDomains'}
In [8]:
resp.url
Out[8]:
'https://news.v.daum.net/v/20190728165812603'
In [ ]: