import urllib.parse as parse import xml.etree.ElementTree as ET import requests from flask import Flask, request app = Flask(__name__) @app.route('/convert_feed_to_oregonian_amp/') def bring_out_feed(): # De-url encode the input url = parse.unquote(request.args.get('url')) oregon = requests.get(url) content = oregon.content root = ET.fromstring(content) for child in root.iter('item'): updated_url = parse.urlparse(child.find('link').text, allow_fragments=True) if updated_url.query != '': updated_url = updated_url._replace(query=updated_url.query + '&') updated_url = updated_url._replace(query=updated_url.query + 'outputType=amp') print(updated_url) child.find('link').text = str(parse.urlunparse(updated_url)) return app.response_class(ET.tostring(root), mimetype='application/xml') print(app.url_map)