The basic usage of the requests module in the Python module is detailed

Source: Internet
Author: User
Tags string format python script
首先还是老生长谈,说说定义和作用,request模块是一个用于访问网络的模块,其实类似的模块还有很多,不在一一在这里解释。这么多的相似的模块为什么都说只有这个好用呢。因为他人性化。如果你学过urllib之类的模块的话,对比一下就很清楚了(文章url以题目实验吧的唯快不破)。

1, no matter what kind of script we all know the first to import the modules we need

2, since this module is to access the network module, we will give him a URL, send a GET request.

Because you are doing a CTF topic, so take the URL of the topic as an example

After sending, we will get this corresponding object re, which is the corresponding information we want. If you do not do any processing output, you will return the requested status code, if you want the content to appear, you need to add. text. Output in string format. Similarly, post delivery is the same.

3. Send request with parameters

Get request: When a GET request is sent, his parameter is the params passed to the keyword. Let's test it.

POST request: When sending a POST request, use data as the keyword parameter to pass the test

4. Get a field in the response header

We can use headers to test this.

Get all fields

Gets the specified field, for example, the title, I want to get the flag field

' Re.headers ' gets a dictionary, we want to get one, and we can get it in this form.

If we want to get the request header, we can re.request.headers it directly and test it.

5, the end of the article, send the topic of the CTF Python script, the topic is the experiment bar of the only fast not broken

Code

The basic usage of the requests module in the Python module is detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.