无法修复类型错误:只能将str(而不是“NoneType”)连接到s

2024-10-05 14:24:38 发布

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

url21 =  "https://www.ft.com/search?sort=date&q=eurozone"
with open(savePath + "Euro_FT" + date + ".txt","wt",-1,'utf-8') as f1:
        ht2 = req.urlopen(url21)
        soup2 = BeautifulSoup(ht2,'html.parser')
        contents = soup2.select('div.o-teaser__heading > a')[0:]
        for i, contents in enumerate(contents,1):
            f1.write(str(i) + " " + contents.string + "\n")

我已经使用上面提到的python代码超过6个月了, 突然我收到了错误消息TypeError: can only concatenate str (not "NoneType") to str

我试图通过stackoverflow问答找到一些答案,但案例和答案与我的案例有点不同。在

我使用了for,而不是{},下面的代码很好地工作。。。。在

^{pr2}$

我已经找了一个多小时了。。但我找不到答案。。。在


Tags: 答案代码httpscomfordatewwwcontents