问题
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 characteru'\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