首先我们先引入requests模块
import requests
一、发送请求
r = requests.get('https://api.github.com/events') # GET请求 r = requests.post('http://httpbin.org/post', data = {'key':'value'}) # POST请求 r = requests.put('http://httpbin.org/put', data = {'key':'value'}) # PUT请求 r = requests.delete('http://httpbin.org/delete') # DELETE请求 r = requests.head('http://httpbin.org/get') # HEAD请求 r = requests.options('http://httpbin.org/get') # OPTIONS请求 type(r)
requests.models.Response
二、传递URL参数
URL传递参数的形式为:httpbin.org/get"htmlcode">
payload = {'key1': 'value1', 'key2': 'value2'} r = requests.get("http://httpbin.org/get", params=payload) print(r.url)
http://httpbin.org/get"htmlcode">payload = {'key1': 'value1', 'key2': ['value2', 'value3']} r = requests.get('http://httpbin.org/get', params=payload) print(r.url)http://httpbin.org/get"htmlcode">url = 'https://api.github.com/some/endpoint' headers = {'user-agent': 'my-app/0.0.1'} r = requests.get(url, headers=headers)更多关于Python爬虫库requests的使用方法请点击下面的相关链接
最新资源
- 伍佰1998《世界第一等》98绝版收藏EP[WAV+CUE]
- 天乐试机天碟 《终极参考SACD》十大发烧唱片之一
- 群星《新说唱2024 第12期 (下)》[320K/MP3][95.
- 楼兰2024-《楼兰传奇》[低速原抓WAV+CUE]
- 楼兰《楼兰传奇2》2024[低速原抓WAV+CUE]
- 陈果《有了你》UPM24K金碟[日本限量版][WAV+CUE
- 群星《新说唱2024 第12期 (下)》[FLAC/分轨][50
- 李常超 (Lao乾妈)《天生江湖》[320K/MP3][168.8
- 李常超 (Lao乾妈)《天生江湖》[FLAC/分轨][633.
- 群星《雨果发烧碟二十》UPMAGCD2024[WAV+CUE]