简体   繁体   English

如何使用Beautiful Soup将汤输出到.html?

[英]How to output soup to .html using Beautiful Soup?

I am parsing a weblink and I want to save the whole webpage to a local file in format .html . 我正在解析一个网络链接,我想将整个网页保存为.html格式的本地文件。 I want to directly output soup to an html file locally for uploading a copy to S3-AWS ? 我想将汤直接输出到本地的html文件中,以将副本上传到S3-AWS吗?

from bs4 import BeautifulSoup
import requests
url_name = "https://<weblink>/"
soup = BeautifulSoup(url_name,"html.parser")

Now, I am just wondering, like .txt can we output soup to .html as well . 现在,我只是想知道,像.txt一样,我们也可以将汤输出到.html as well吗? Suggestions appreciated. 建议表示赞赏。

You imported requests but never actually used it. 您导入了请求,但从未实际使用过。 You need to GET the actual site 您需要获取实际站点

r=requests.get(url_name)

Then you can pass that to BS 然后可以将其传递给BS

soup=BeautifulSoup(r.text,'html.parser')

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM