# Issue importing BeautifulSoup into a script

**URL:** <https://discourse.mitmproxy.org/t/issue-importing-beautifulsoup-into-a-script/324>\
**Category:** help\
**Created:** [January 27, 2017, 2:40am UTC](https://discourse.mitmproxy.org/t/issue-importing-beautifulsoup-into-a-script/324 "2017-01-27T02:40:49Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![pythonnovice](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@pythonnovice](https://discourse.mitmproxy.org/u/pythonnovice)\
**Post date:** [January 27, 2017, 2:40am UTC](https://discourse.mitmproxy.org/t/issue-importing-beautifulsoup-into-a-script/324/1 "2017-01-27T02:40:50Z")

</div>

I’m trying to get BeautifulSoup imported into a mitmdump script and am stuck. I’ve verified that b4 is installed in the same python runtime that mitmdump is executing and even tried forcing the path using os.environ[‘PYTHONPATH’] inside the script. doesn’t work.

Fails with this error:

```
Script error: Traceback (most recent call last):
  File "script.py", line 9, in <module>
    from b4 import BeautifulSoup
ImportError: No module named 'b4'

```

Please help!

```
import sys
from mitmproxy import io
import os

    #import pdb; pdb.set_trace()

    from b4 import BeautifulSoup

    class Writer:
        def __init__ (self, path):
            self.f = open(path, "wb")

        def response(self, flow):
            self.f.write( bytes(flow.request.url,'utf-8'))
            soup = BeautifulSoup(flow.response.content, 'html.parser')
            self.f.write( flow.response.content )

    def start():
        return Writer("out")
```

---

<div class="post-metadata">

**Author:** ![pythonnovice](https://avatars.discourse-cdn.com/v4/letter/p/278dde/32.png) [@pythonnovice](https://discourse.mitmproxy.org/u/pythonnovice)\
**Post date:** [January 27, 2017, 12:41pm UTC](https://discourse.mitmproxy.org/t/issue-importing-beautifulsoup-into-a-script/324/2 "2017-01-27T12:41:42Z")

</div>

Never mind, I’m an idiot, looking at the mitmscript that brew installs, I saw “cellar” in the file path and skipped to the assumption that it was brew’s copy of python rather than it’s own executable.

putting  
/usr/local/Cellar/mitmproxy/1.0.2/libexec/bin/

first in my path and correctly setting PYTHONPATH to  
/usr/local/Cellar/mitmproxy/1.0.2/libexec/lib/python3.6

and then running  
pip3 install BeautifulSoup4

fixed the issue.
