python post request
#-*-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
阅读更多
版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/feihuadao/article/details/51543706
文章标签: python http
个人分类: python
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

不良信息举报

python post request

最多只允许输入30个字

加入CSDN,享受更精准的内容推荐,与500万程序员共同成长!
关闭
关闭