#-*-coding:utf-8-*-
import requests
import traceback
import json
import time
try:
url = "https://www.baidu.com/"
headers = {'Accept': 'text/html, application/xhtml+xml, */*',
'Accept-Language':'zh-CN',
'User-Agent':'Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; rv:11.0) like Gecko',
'Host':'baidu.com',
'Cache-Control':'no-cache',
'Content-Type': 'application/x-www-form-urlencoded',
'Referer':'https://www.baidu.com',
'Cookie':'',
'Connection': 'Keep-Alive',
'Accept-Encoding': 'gzip,deflate'}
r = requests.post(url, data = '',headers=headers)
s = r.content
f = open('tst.html','w')
f.write(s)
f.close()
print(s.decode('utf-8').encode('gb18030'))
except Exception as e:
print(e)
print(traceback.format_exc())
pass
python post request
最新推荐文章于 2024-04-15 18:10:34 发布