python-aiohttpHow to get headers using Python Aiohttp?
Using Python Aiohttp, you can get headers from a web page by making a GET request.
import aiohttp
async with aiohttp.ClientSession() as session:
async with session.get('https://www.example.com') as response:
print(response.headers)
{'Content-Type': 'text/html; charset=UTF-8', 'Date': 'Sun, 28 Jun 2020 11:45:02 GMT', 'Server': 'Apache', 'Vary': 'Accept-Encoding', 'X-Powered-By': 'PHP/7.2.24', 'Content-Length': '1256', 'Connection': 'close'}
import aiohttp
: imports the aiohttp library.async with aiohttp.ClientSession() as session
: creates a ClientSession object.async with session.get('https://www.example.com') as response
: makes a GET request to the specified URL.print(response.headers)
: prints the response headers.
Helpful links
Related
- How to handle x-www-form-urlencoded with Python Aiohttp?
- How to create a websocket server using Python Aiohttp?
- How to create a JSON response using Python Aiohttp?
- How to create a connection pool with Python Aiohttp?
- How to check if a session is closed with Python Aiohttp?
- How to create a server with Python Aiohttp?
- How to reuse a session with Python Aiohttp?
- How to download large files with Python Aiohttp?
- How to redirect with Python Aiohttp?
- How to use Gzip with Python Aiohttp?
More of Python Aiohttp
- How to handle x-www-form-urlencoded with Python Aiohttp?
- How to create a websocket server using Python Aiohttp?
- How to use HTTP2 with Python Aiohttp?
- How to redirect with Python Aiohttp?
- How to create a JSON response using Python Aiohttp?
- How to get response text with Python Aiohttp?
- How to set headers in Python Aiohttp?
- How to check if a session is closed with Python Aiohttp?
- How to create a server with Python Aiohttp?
- How to reuse a session with Python Aiohttp?
See more codes...