request 模块学习

耗尽温柔 提交于 2020-01-07 15:39:04

1、get请求

import requests

def lx(url,headers):
    response = requests.get(url=url ,headers=headers)
    if response.status_code == 200:
        print(response.text)
    return None

if __name__ == '__main__':
    url = 'https://www.9k9k.com/shouyou/rmjh_98915.html'
    headers = {'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.87 Safari/537.36'}
    lx(url=url,headers=headers)

 

2、post请求

impot request

def login(email, password, _xsrf, captcha):
    data = {
        '_xsrf': _xsrf,
        'password': password,
        'email': email,
        'captcha': captcha
    }
    login_url = 'https://www.zhihu.com/login/email'
    response = session.post(login_url, data=data, headers=headers)
        if response.status_code == 200:
        print(response.text)
    return None
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!