Beautfil Soup Error with simple script
Question: I am running Beautiful Soup 4.5 with Python 3.4 on Windows 7. Here is my
script:

    
    
    from bs4 import BeautifulSoup
    import urllib3
    
    http = urllib3.PoolManager()
    
    url = 'https://scholar.google.com'
    response = http.request('GET', url)
    html2 = response.read()
    soup = BeautifulSoup([html2])
    
    print (type(soup))
    

Here is the error I am getting:

> TypeError: Expected String or Buffer

I have researched and there seem to be no fixes except going to an older
version of Beautiful Soup which I don't want to do. Any help would be much
appreciated.


Answer: Not sure why are you putting the html string into the list here:

    
    
    soup = BeautifulSoup([html2])
    

Replace it with:

    
    
    soup = BeautifulSoup(html2)
    

Or, you can also pass the response file-like object, `BeautifulSoup` would
read it for you:

    
    
    response = http.request('GET', url)
    soup = BeautifulSoup(response)
    

* * *

It is also a good idea to _specify a parser explicitly_ :

    
    
    soup = BeautifulSoup(html2, "html.parser")
    

