Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How does python call api?

2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report