Skip to main content
 首页 » 编程设计

python之TypeError : argument 1 must be convertible to a buffer, 不是 BeautifulSoup

2025年05月04日32kerrycode

from bs4 import BeautifulSoup 
import requests 
import csv 
 
 
page=requests.get("http://www.gigantti.fi/catalog/tietokoneet/fi_kannettavat/kannettavat-tietokoneet") 
 
data=BeautifulSoup(page.content) 
 
h=open("test.csv","wb+") 
h.write(data) 
h.close() 
 
print (data) 

我已经尝试按原样运行代码而不将其打印在 csv 文件中并且它运行完美但是当我尝试将它保存在 csv 中时我收到错误:参数 1 必须可转换为缓冲区,而不是 BeautifulSoup。请帮助并提前致谢

请您参考如下方法:

我不知道是否有人能够解决它,但我的命中和试用成功了。问题是我没有将内容转换为字符串。

#what i needed to add was: 
#after line data=BeautifulSoup(page.content) 
a=str(data) 

希望对你有帮助