python 的自带库 urllib
import urllib.request
import urllib.parse
get_url = 'http://www.baidu.com'
def get_request():
ru = urllib.request.Request(url=url)
print('ru: ', ru) # 对象
ru_response = urllib.request.urlopen(ru)
print('ru_response: ', ru_response) #
print('getcode: ', ru_response.getcode())
print('headers: ', ru_response.headers)
# get_request()
post_url = 'http://www.tuling123.com/openapi/api'
post_data = {
'key': "Your",
'info': '你好'
}
def post_request():
data = urllib.parse.urlencode(post_data).encode('utf-8')
rp = urllib.request.Request(post_url, data)
rp_response = urllib.request.urlopen(rp)
print('getcode: ', rp_response.getcode())
print('msg', rp_response.msg)
print('read', rp_response.read())
# post_request()