如何格式化凌乱的html源代码?python

2024-05-19 14:42:18 发布

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

我用python编写了使用HTML源代码的代码,使用BeautifulSoup。 我得到的HTML非常混乱。如何使HTML源代码看起来很好?你知道吗

这是website

这就是我如何获取html源代码(其中的一部分):

    property="article:tag" content="ally" /><meta
property="article:tag" content="harvey weinstein" /><meta
property="article:tag" content="pratiksha parulekar" /><meta
property="article:tag" content="rape culture" /><meta
property="article:section" content="No Photo" /><meta
property="article:published_time" content="2017-10-25T22:28:46-05:00" /><meta
property="article:modified_time" content="2017-10-25T22:44:29-05:00" /><meta
property="og:updated_time" content="2017-10-25T22:44:29-05:00" /><meta
name="twitter:card" content="summary" /><meta
name="twitter:description" content="For men, professing disgust at sexual assault allegations is not sufficient; male allies must also hold friends who harass women accountable." /><meta
name="twitter:title" content="To combat sexual harassment, men must hold peers accountable &bull; The Tulane Hullabaloo" /><link
rel='dns-prefetch' href='//cdn.jsdelivr.net' /><link
rel='dns-prefetch' href='//maxcdn.bootstrapcdn.com' /><link
rel='dns-prefetch' href='//fonts.googleapis.com' /><link
rel='dns-prefetch' href='//s.w.org' /><link

我能做什么?你知道吗


Tags: name源代码timednshtmltagarticlelink
2条回答

如果您想“美化”HTML,因为您正在使用BeautifulSoup,您可以在here中做一些事情。你知道吗

请记住,自回答之后,导入已发生变化,现在是:

from bs4 import BeautifulSoup

可能有些字段从此发生了更改,您可以找到更多示例in the documentation

你可能在找the doc

print(yoursoup.prettify())

相关问题 更多 >