pywebcopy复制的网站是有什么解决办法吗?

pywebcopy复制的网站是有什么解决办法吗?

python3.9

程序如下:

    from pywebcopy import save_webpage

save_webpage(

url='http://www.hippter.com/',

project_folder='D:/Python/script',

project_name='my_site3',

bypass_robots=True,# 调试

debug=True,

open_in_browser=True,# 在浏览器中打开

delay=None,# 延迟

threaded=False,# 线程

)

问题:

 如何显示中文,不出现乱码?


回答:

第三方库:

from bs4 import BeautifulSoup

with open('path/to/your/saved/html/file.html', 'r', encoding='utf-8') as file:

soup = BeautifulSoup(file, 'html.parser')

if soup.meta:

soup.meta['charset'] = 'utf-8'

else:

soup.head.append(soup.new_tag('meta', charset='utf-8'))

with open('path/to/your/saved/html/file.html', 'w', encoding='utf-8') as file:

file.write(str(soup))

以上是 pywebcopy复制的网站是有什么解决办法吗? 的全部内容, 来源链接: utcz.com/p/939014.html

回到顶部