# Pip3 install using pip or requests library
pip3 install requests
#requests library:
python python # input into the command line
run the following code in order cmd command line, or you can start directly in PyCharm in:
Import requests # import requests library # addition request header headers = { ' the User-- Agent ' : ' the Mozilla / 5.0 (the Windows NT 10.0; Win64; x64-) AppleWebKit / 537.36 (KHTML, like the Gecko) the Chrome / 80.0.3987.122 Safari / 537.36 ' } # URL is defined as Baidu URL = ' http://www.baidu.com ' # call requests get function library response = requests.get (URL, headers = headers) # call packet requests, call the get method # View status response whether the code 200 is Print (response.status_code) # obtain baidu source Print (response.text)
Response code 200 is obtained and the source code Baidu