Python存HTML文件

it2026-04-17  0

file_name = 'test--------' url = 'https://www.londonstockexchange.com/news-article/RCP/annual-financial-report/13989778' def getHtml(url): html = urllib.request.urlopen(url,timeout=10).read() return html def saveHtml(file_name, file_content): with open(file_name + ".html", "wb") as f: # 写文件用bytes而不是str,所以要转码 f.write(file_content) html = getHtml(url) saveHtml(file_name, html) print("下载成功")

 

最新回复(0)