Skip to main content
 首页 » 编程设计

python之写入 excel 文件时超过 url 数量

2024年11月24日9rubylouvre

我收到了这个警告 WARNING: C:\Users\diodi\AppData\Local\Programs\Python\Python37-32\lib\site-packages\xlsxwriter\worksheet.py:923: UserWarning: Ignoring URL ' https://www.google.com/search?q=hello+world' 因为它超过了 Excel 对每个工作表 65,530 个 URL 的限制。 “每个工作表 65,530 个 URL。” % force_unicode(url))

我用来写抓取数据的输出

#spider.found_items is a list of dictionary 
df = pd.DataFrame(spider.found_items)[ordered_list] #ordered_list is the order of dictiornary outputed 
df.to_excel("{}.xlsx".format(file_name),sheet_name='All Products') 

我检查了这个Number of URLS is over Excel's limit of 65,530 URLS per worksheet.但这会将链接格式化为字符串(不可点击)。如果我可以写多张纸或任何其他建议,有没有办法保留 URL(作为链接)?

请您参考如下方法:

从根本上说,这是 Excel 的限制。每个工作表仅允许 65,530 个唯一* url。没有任何解决方法。

(*) 如果连续分组,Excel 允许超过 65,530 个非唯一 url。例如,单元格 A1 到 A100 中的相同网址将仅计为一个网址,超出 65,530 个限制。但是,XlsxWriter 不支持对 url 进行分组以利用这一点(即使支持,如果所有 url 都是唯一的或不连续的,也无济于事)。