# How to parse xml response

**URL:** <https://discourse.mitmproxy.org/t/how-to-parse-xml-response/710>\
**Category:** help\
**Created:** [November 14, 2017, 2:27am UTC](https://discourse.mitmproxy.org/t/how-to-parse-xml-response/710 "2017-11-14T02:27:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![OlivierMedor](https://avatars.discourse-cdn.com/v4/letter/o/ad7895/32.png) [@OlivierMedor](https://discourse.mitmproxy.org/u/OlivierMedor)\
**Post date:** [November 14, 2017, 2:27am UTC](https://discourse.mitmproxy.org/t/how-to-parse-xml-response/710/1 "2017-11-14T02:27:31Z")

</div>

Hello,

I am fairly new to mitmproxy, proxy/network related topics and also python. Though I am not so great at it, i managed to get some scripts started. I ran into a snag. Not sure if this is a mitmproxy issue or a python issue for me. Basically, what i am trying to accomplish is I want to parse the flow.response.body using regex. I am having a hard time because the response flow.response.body is an xml response. Here is an example of what i would like to do below. Can someone help me to do it the correct way?

Thank you

```
import xml.etree.ElementTree as ET
import re

def response(context, flow):
        requestUrl = flow.request.url
        if 'https://blahblahblah.com' == requestUrl:
        				tree = ET.parse(flow.response.body)
        				root = tree.getroot()
        				responseString = ET.tostring(root).decode('utf-8')
        				parsedVal = re.findall(r'(?<=over.).*?(?=here)', responseString)
        				print('this is the paresed value ' + parsedVal)
```

---

<div class="post-metadata">

**Author:** ![OlivierMedor](https://avatars.discourse-cdn.com/v4/letter/o/ad7895/32.png) [@OlivierMedor](https://discourse.mitmproxy.org/u/OlivierMedor)\
**Post date:** [November 23, 2017, 4:32pm UTC](https://discourse.mitmproxy.org/t/how-to-parse-xml-response/710/2 "2017-11-23T16:32:58Z")

</div>

Basically i want to campture and change the xml payload to an new xml. But I need to keep the rest of the xml request the same as the first xml request. Any one has a suggestion it would be appreciated.

Thank You
