Archive
Posts Tagged ‘_detectEncoding’
BeautifulSoup: _detectEncoding error
September 30, 2012
Leave a comment
Problem
While parsing an HTML page with BeautifulSoup, I got a similar error message:
File ".../BeautifulSoup.py", line 1915, in _detectEncoding
'^<\?.*encoding=[\'"](.*?)[\'"].*\?>').match(xml_data)
TypeError: expected string or buffer
In the code I had this:
text = get_page(url) soup = BeautifulSoup(text)
Solution
text = get_page(url) text = str(text) # here is the trick soup = BeautifulSoup(text)
Tip from here.
Categories: python
beautifulsoup, _detectEncoding
