Python BeautifulSoup 编码
我有一个代码可以使用 Beautiful Soup 读取 html 并修改一些文本。它工作正常,但是当我读取输出时,我的 html 文件的这一部分会自动更改:
Original :
自行修改:
我不希望任何文件内容自动更改。有人可以帮我解决这个问题吗?
这是我的代码:
import re
import sys
from BeautifulSoup import BeautifulSoup
f = open(sys.argv[1],"rw")
data = f.read()
soup = BeautifulSoup(data)
comma = re.compile(',')
for t in soup.findAll(text=comma): t.replaceWith(t.replace(',', '&sbquo'))
print soup
I have a code to read the html and modify some text using Beatiful Soup. It works fine but when I read the output, this part of my html file is changed automatically:
Original : <meta http-equiv="Content-Type" content="text/html; charset=**iso-8859-1**" />
Modified by itself: <meta http-equiv="Content-Type" content="text/html; charset=**utf-8**" />
I don't want any of the file contents to change automatically. Can someone help me with this.
Here is my code:
import re
import sys
from BeautifulSoup import BeautifulSoup
f = open(sys.argv[1],"rw")
data = f.read()
soup = BeautifulSoup(data)
comma = re.compile(',')
for t in soup.findAll(text=comma): t.replaceWith(t.replace(',', '&sbquo'))
print soup
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
尝试
Try