Curso-lenguaje-python/python-ofensivo/08_librerias/03_requests_04_json.py

16 lines
299 B
Python
Raw Normal View History

2024-01-14 00:15:52 +01:00
#!/usr/bin/env python3
import requests
response = requests.get('https://httpbin.org/get')
data = response.json()
if 'headers' in data and 'User-Agent' in data['headers']:
user_agent = data['headers']['User-Agent']
else:
print(f"\n[!] No existe el campo User-Agent en la respuesta\n")