Get the App
SLTechnology News&Howtos  ›  Development  › 

How does python call api?

Shulou Source: shulou.com Published: 2022-05-31 17:45:57 11月01日 Update

This article mainly explains "python how to call api", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "python how to call api" bar!

The operating environment of this tutorial: windows7 system, Python 3.9.1 Dell G3 computer.

1. Description

Api API call refers to access using python's requests library, which is basically a get or post request. Some APIs will be encrypted, and then we must use the public key provided by the other party to encrypt or decrypt, with corresponding parameters for access. The data we need is basically parsed in json format in the return result after the request, so you can use the json function that comes with requests to parse the request. Then extract the required data, and you can get one data at a time.

2. Examples

# encoding: utf-8import requestsimport os,reimport urllib.request data= {"email": "251910179@qq.com", "password": "ydd4903087"} session = requests.session () session.post ("http://www.renren.com/PLogin.do",data= data" Verify = False) response = session.get ("http://www.renren.com/410043129/profile")print (response.text) print (response.url) print (response.status_code) print (response.headers) # climb web photo: requset=requests.post (" http://tieba.baidu.com/p/4114581614", " (http://imgsrc.baidu.com/.*?\.jpg)"'#r=r'http://imgsrc.baidu.com/.+?\.jpg'mylist=re.findall(r,str(requset.text))print (mylist) j=0for i in mylist: urllib.request.urlretrieve (I, "C:/Users/Administrator/Desktop/img1/" + str (j) + ".jpg") thank you for your reading. The above is the content of "how python calls api". After the study of this article, I believe you have a deeper understanding of how python calls api, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Data learning content interfaces encryption public keys functions parameters pictures examples each other that is ideas situations tutorials articles more formats environments computers Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker OPPO Reno vpn Shulou Tech Info Apple