Mechanize and Beautiful soup python

你。 提交于 2019-12-10 12:02:01

问题


I'm trying to submit a form to a site using beautiful soup and mechanize.

Mechanize on its own throws an error with nested forms so I tried following the suggestion of using another parser. Here's the code:

    browser = mechanize.Browser()
    browser.addheaders = [('User-agent', 'Mozilla/5.0 (X11; U; Linux i686; en-US;      rv:1.9.0.1) Gecko/2008071615 Fedora/3.0.1-1.fc9 Firefox/3.0.1')]
    browser.set_handle_robots(False)
    response = browser.open('URL')
    soup = BeautifulSoup(response.get_data())
    response.set_data(soup.prettify())
    browser.set_response(response)

However I'm getting the following error:

UnicodeEncodeError: 'ascii' codec can't encode character u'\xbb' in position 2006: ordinal not in range(128)

for this line of code : response.set_data(soup.prettify())

I'm not quite sure what error being thrown is here if its a problem with types ?

来源:https://stackoverflow.com/questions/14204372/mechanize-and-beautiful-soup-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!