【发布时间】:2019-06-17 06:34:37
【问题描述】:
我编写了这个小代码来从 excel 工作簿中的 url 列表中拆分域。但问题是我无法将其写入实际工作簿,甚至无法使用域创建新工作簿。
#looping it
for i in range(2, 200):
print((sheet.cell(row=i, column=1).value).split('http://')[-1].split('/')[0].split('www.')[-1])
#but by this i have to go copy paste the results in the excel sheet
#so i tried this replace value method but it keeps showing attribute error
for x in range(2, 258):
sheet.cell(row=x, column=1).value = sheet.cell(row=x, column=1).value.split('http://')[-1].split('/')[0].split('www.')[-1]
Traceback (most recent call last):
File "<pyshell#63>", line 2, in <module>
sheet.cell(row=x, column=1).value = sheet.cell(row=x, column=1).value.split('http://')[-1].split('/')[0].split('www.')[-1]
AttributeError: 'NoneType' object has no attribute 'split'
我希望这个循环遍历列表并将 url(htts://www.example.com/example-page/) 拆分为域(example.com) 并将其保存在同一张表或新表中一世 用这个
wb.save('domains_list')
#it saves the splitted domains automatically without me copy pasting it from idle to excel workbook.
【问题讨论】:
-
您的某些单元格不包含任何字符串。
标签: python excel openpyxl attributeerror nonetype