Python编码问题与beautifulsoup

2024-10-01 17:31:02 发布

您现在位置:Python中文网/ 问答频道 /正文

你好,我有个问题是什么编码

当我把琴弦放到美丽的曲调上时,失去了所有的民族性格

addr = "http://zjazdowa.com.pl/index.php/aktualne-ceny-warzyw-i-owocow-.html"                                
content = urllib2.urlopen(addr) .read()
html_pag = BeautifulSoup(content) #<- there i lost all national letters 
table_html= html_pag.find("div",  id="808") 

在头文件中我有:

^{pr2}$

Tags: comhttp编码indexhtmlcontentaddrpl
2条回答

你的代码非常好用:

>>> addr = "http://zjazdowa.com.pl/index.php/aktualne-ceny-warzyw-i-owocow-.html"                                
>>> content = urllib2.urlopen(addr) .read()
>>> html_pag = BeautifulSoup(content) #<- there i lost all national letters 
>>> table_html= html_pag.find("div",  id="808")
>>> print table_html.findAll('td')[8].string
Kapusta włoska

对此,请注意:

^{pr2}$

reload重新加载模块。我不知道你希望通过重新加载sys来做什么,但它不会给你带来任何好处。在

根据BeautifulSoup的文档,所有输入都在内部转换为UTF8:

from BeautifulSoup import BeautifulSoup
soup = BeautifulSoup("Hello")
soup.contents[0]
# u'Hello'
soup.originalEncoding
# 'ascii'

如果您的输入没有指定编码(例如,meta标记),beauthoulsoup会猜测。您可以通过fromEncoding参数指定输入的编码来禁用猜测:

^{pr2}$

或者你真正的问题是结果到控制台的“中断”输出?在

相关问题 更多 >

    热门问题