解析时URL返回编码值

时间:2015-09-30 19:43:08

标签: python web-scraping beautifulsoup mechanize mechanize-python

我正在使用Mechanize打开一个URL,我正在用BeautifulSoup解析它。

br = mechanize.Browser()
br.addheaders = [('User-agent', 'Mozilla/5.0')]
url = ('xyz.html')
br.open(url)
print br.response().read() #prints four special characters
soup = BeautifulSoup(br.response().read()) 
print soup #prints encoded data

如果我在本地复制HTML文件然后解析它,则不会发生此问题。

一旦我通过机械化检索它,我应该解码/编码吗?如果是这样,我该怎么做?

0 个答案:

没有答案
相关问题