我正在尝试从https://finansial.bisnis.com/read/20210506/90/1391096/laba-bank-mega-tumbuh-dua-digit-kuartal-i-2021-ini-penopangnya. 我正在尝试抓取新闻的日期,这是我的代码:
news['tanggal'] = newsScrape['date']
dates = []
for x in news['tanggal']:
x = listToString(x)
x = x.strip()
x = x.replace('\r', '').replace('\n', '').replace(' \xa0|\xa0', ',').replace('|', ', ')
dates.append(x)
dates = listToString(dates)
dates = dates[0:20]
if len(dates) == 0:
continue
news['tanggal'] = dt.datetime.strptime(dates, '%d %B %Y, %H:%M')
但我收到了这个错误:
ValueError: time data '06 Mei 2021, 11:32 ' does not match format '%d %B %Y, %H:%M'
我的假设是因为Mei是印度尼西亚语,同时格式需要May是英语。怎么变Mei是May?我已经尝试过dates = dates.replace('Mei', 'May'),但它对我不起作用。当我尝试它时,我得到了错误ValueError: unconverted data remains: 日期的类型是string。谢谢