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
,而不是if
,下面的代码效果很好。...
url21 = "https://www.ft.com/world/europe"
with open(savePath + "europe_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")
我已经尝试并搜索了一个多小时。.但是我找不到答案...