【发布时间】:2021-04-16 13:33:33
【问题描述】:
这是我从网站获得的 JSON:
[
{
"id":"8-23p-0",
"step":"",
"html":"<p>1</p>",
"link":"",
"commentCount":0
},
{
"id":"8-23p-1",
"step":"1",
"html":"<p>2</p>",
"link":"",
"commentCount":0
},
{
"id":"8-23p-2",
"step":"2",
"html":"<p>3</p>",
"link":"",
"commentCount":0
},
{
"id":"8-23p-3",
"step":"3",
"html":"<p>4</p>",
"link":"",
"commentCount":0
},
{
"id":"8-23p-4",
"step":"4",
"html":"<p>5</p>",
"link":"",
"commentCount":0
}
]
我正在编写此代码以从中获取所有 HTML
html_values = []
for i in answer2:
html_values.append(i.get("html"))
通过上面的代码,我得到了所有列表类型的 html
但我想为每个步骤添加一个标题,例如:
预期输出:
<h>step 1</h>
<p>1</p>
<h>step 2</h>
<p>2</p>
<h>step 3</h>
<p>3</p>
<h>step 4</h>
<p>4</p>
<h>step 5</h>
<p>5</p>
我想得到上面的输出,请帮助我,谢谢
【问题讨论】:
-
为什么你的 p 值都是 5?
标签: python beautifulsoup python-requests