print(response.text)出现,{"words_result":[{"words":"<title>自贝框</title>"},{"words":"</head>"},{"words":"<body>"},{"words":"<div class=\"ui three column grid\">"},{"words":"<div class=\"two wide column\"></div>"},{"words":"<div class=\"twelve wide column\">"},{"words":"<img class=\"ui image\" src=\"banner. jpg\">"},{"words":"<div class=\"ui vertical segment\">"},{"words":"<div class=\"ui seven item menu\">"},{"words":"<a href=\"#\" class=\"item\">首页</a>"},{"words":"<a href=\"#\" class=\"item\">1</a>"},{"words":"<a href=\"#\" class=\"item\">2</a>"},{"words":"<a href=\"#\" class=\"item\">3</a>"},{"words":"<a href=\"#\" class=\"item\">4</a>"},{"words":"<a href=\"#\" class=\"item\">5</a>"},{"words":"<a href=\"#\" class=\"item\">6</a>"},{"words":"</div>"},{"words":"<div class=\"ui vertical segment\">"},{"words":"</div>"},{"words":"<div class=\"ui vertical segment\">3</div>"},{"words":"<div class=\"ui vertical segment\">4</div>"},{"words":"<div class=\"ui vertical segment\">5</div>"}],"words_result_num":22,"log_id":1667739582476171051},如何 提取里面真正的内容
时间: 2023-07-08 08:52:54 浏览: 79
初学者scrapy框架爬取数据不成功,出现ERROR: Spider error processing错误问题的解决方法
可以使用 Python 的 json 库来提取其中的内容。先将 response.text 转换为字典格式,然后就可以通过字典的键值对来获取需要的内容了。例如,可以通过以下代码提取网页的标题:
```python
import json
# 将 response.text 转换为字典格式
result = json.loads(response.text)
# 提取网页的标题
title = result['words_result'][0]['words']
print(title)
```
类似地,可以通过修改键值对中的索引来提取其他内容。
阅读全文