soup = BeautifulSoup(response.text, 'html.parser')转为utf-8
时间: 2023-10-28 10:20:19 浏览: 215
如果你想将 `soup` 对象转为 utf-8 编码,可以使用 `encode()` 方法。具体操作如下:
```python
soup = BeautifulSoup(response.text, 'html.parser')
utf8_str = soup.encode('utf-8')
```
这样,`utf8_str` 就是 utf-8 编码的字符串了。如果你想将其写入文件,可以使用以下代码:
```python
with open('filename.txt', 'wb') as file:
file.write(utf8_str)
```
其中,`filename.txt` 是你要写入的文件名。
阅读全文
相关推荐





