Spaces:
Build error
Build error
File size: 605 Bytes
083ada9 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | import requests
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route('/fetch', methods=['POST'])
def fetch_url_content():
data = request.json
target_url = data.get('url')
if not target_url:
return jsonify({"error": "No URL provided"}), 400
try:
response = requests.get(target_url)
return jsonify({
"status_code": response.status_code,
"content": response.text
})
except Exception as e:
return jsonify({"error": str(e)}), 500
if __name__ == '__main__':
app.run(host='0.0.0.0', port=7860)
|