xjc 4 tahun lalu
melakukan
9cdb19a286
100 mengubah file dengan 136 tambahan dan 0 penghapusan
  1. 24 0
      demo.py
  2. 112 0
      parsedocx.py
  3. TEMPAT SAMPAH
      test.docx
  4. TEMPAT SAMPAH
      test4.docx
  5. TEMPAT SAMPAH
      test4.files/image001.gif
  6. TEMPAT SAMPAH
      test4.files/image001.png
  7. TEMPAT SAMPAH
      test4.files/image002.gif
  8. TEMPAT SAMPAH
      test4.files/image002.png
  9. TEMPAT SAMPAH
      test4.files/image003.gif
  10. TEMPAT SAMPAH
      test4.files/image003.png
  11. TEMPAT SAMPAH
      test4.files/image004.gif
  12. TEMPAT SAMPAH
      test4.files/image004.png
  13. TEMPAT SAMPAH
      test4.files/image005.gif
  14. TEMPAT SAMPAH
      test4.files/image005.png
  15. TEMPAT SAMPAH
      test4.files/image006.gif
  16. TEMPAT SAMPAH
      test4.files/image006.png
  17. TEMPAT SAMPAH
      test4.files/image007.gif
  18. TEMPAT SAMPAH
      test4.files/image007.png
  19. TEMPAT SAMPAH
      test4.files/image008.gif
  20. TEMPAT SAMPAH
      test4.files/image008.png
  21. TEMPAT SAMPAH
      test4.files/image009.gif
  22. TEMPAT SAMPAH
      test4.files/image009.png
  23. TEMPAT SAMPAH
      test4.files/image010.gif
  24. TEMPAT SAMPAH
      test4.files/image010.png
  25. TEMPAT SAMPAH
      test4.files/image011.gif
  26. TEMPAT SAMPAH
      test4.files/image011.png
  27. TEMPAT SAMPAH
      test4.files/image012.gif
  28. TEMPAT SAMPAH
      test4.files/image012.png
  29. TEMPAT SAMPAH
      test4.files/image013.gif
  30. TEMPAT SAMPAH
      test4.files/image013.png
  31. TEMPAT SAMPAH
      test4.files/image014.gif
  32. TEMPAT SAMPAH
      test4.files/image014.png
  33. TEMPAT SAMPAH
      test4.files/image015.gif
  34. TEMPAT SAMPAH
      test4.files/image015.png
  35. TEMPAT SAMPAH
      test4.files/image016.gif
  36. TEMPAT SAMPAH
      test4.files/image016.png
  37. TEMPAT SAMPAH
      test4.files/image017.gif
  38. TEMPAT SAMPAH
      test4.files/image017.png
  39. TEMPAT SAMPAH
      test4.files/image018.gif
  40. TEMPAT SAMPAH
      test4.files/image018.png
  41. TEMPAT SAMPAH
      test4.files/image019.gif
  42. TEMPAT SAMPAH
      test4.files/image019.png
  43. TEMPAT SAMPAH
      test4.files/image020.gif
  44. TEMPAT SAMPAH
      test4.files/image020.png
  45. TEMPAT SAMPAH
      test4.files/image021.gif
  46. TEMPAT SAMPAH
      test4.files/image021.png
  47. TEMPAT SAMPAH
      test4.files/image022.gif
  48. TEMPAT SAMPAH
      test4.files/image022.png
  49. TEMPAT SAMPAH
      test4.files/image023.gif
  50. TEMPAT SAMPAH
      test4.files/image023.png
  51. TEMPAT SAMPAH
      test4.files/image024.gif
  52. TEMPAT SAMPAH
      test4.files/image024.png
  53. TEMPAT SAMPAH
      test4.files/image025.gif
  54. TEMPAT SAMPAH
      test4.files/image025.png
  55. TEMPAT SAMPAH
      test4.files/image026.gif
  56. TEMPAT SAMPAH
      test4.files/image026.png
  57. TEMPAT SAMPAH
      test4.files/image027.gif
  58. TEMPAT SAMPAH
      test4.files/image027.png
  59. TEMPAT SAMPAH
      test4.files/image028.gif
  60. TEMPAT SAMPAH
      test4.files/image028.png
  61. TEMPAT SAMPAH
      test4.files/image029.gif
  62. TEMPAT SAMPAH
      test4.files/image029.png
  63. TEMPAT SAMPAH
      test4.files/image030.gif
  64. TEMPAT SAMPAH
      test4.files/image030.png
  65. TEMPAT SAMPAH
      test4.files/image031.gif
  66. TEMPAT SAMPAH
      test4.files/image031.png
  67. TEMPAT SAMPAH
      test4.files/image032.gif
  68. TEMPAT SAMPAH
      test4.files/image032.png
  69. TEMPAT SAMPAH
      test4.files/image033.gif
  70. TEMPAT SAMPAH
      test4.files/image033.png
  71. TEMPAT SAMPAH
      test4.files/image034.gif
  72. TEMPAT SAMPAH
      test4.files/image034.png
  73. TEMPAT SAMPAH
      test4.files/image035.gif
  74. TEMPAT SAMPAH
      test4.files/image035.png
  75. TEMPAT SAMPAH
      test4.files/image036.gif
  76. TEMPAT SAMPAH
      test4.files/image036.png
  77. TEMPAT SAMPAH
      test4.files/image037.gif
  78. TEMPAT SAMPAH
      test4.files/image037.png
  79. TEMPAT SAMPAH
      test4.files/image038.gif
  80. TEMPAT SAMPAH
      test4.files/image038.png
  81. TEMPAT SAMPAH
      test4.files/image039.gif
  82. TEMPAT SAMPAH
      test4.files/image039.png
  83. TEMPAT SAMPAH
      test4.files/image040.gif
  84. TEMPAT SAMPAH
      test4.files/image040.png
  85. TEMPAT SAMPAH
      test4.files/image041.gif
  86. TEMPAT SAMPAH
      test4.files/image041.png
  87. TEMPAT SAMPAH
      test4.files/image042.gif
  88. TEMPAT SAMPAH
      test4.files/image042.png
  89. TEMPAT SAMPAH
      test4.files/image043.gif
  90. TEMPAT SAMPAH
      test4.files/image043.png
  91. TEMPAT SAMPAH
      test4.files/image044.gif
  92. TEMPAT SAMPAH
      test4.files/image044.png
  93. TEMPAT SAMPAH
      test4.files/image045.gif
  94. TEMPAT SAMPAH
      test4.files/image045.png
  95. TEMPAT SAMPAH
      test4.files/image046.gif
  96. TEMPAT SAMPAH
      test4.files/image046.png
  97. TEMPAT SAMPAH
      test4.files/image047.gif
  98. TEMPAT SAMPAH
      test4.files/image047.png
  99. TEMPAT SAMPAH
      test4.files/image048.gif
  100. 0 0
      test4.files/image048.png

+ 24 - 0
demo.py

@@ -0,0 +1,24 @@
+#!-*-coding:utf-8 -*-
+from win32com.client import Dispatch
+
+word = Dispatch('Word.Application')
+word.Visible = 0
+doc = word.Documents.Open("D:\\docxdemo\\test4.docx")
+
+doc.SaveAs("D:\\docxdemo\\test4.html",10)
+doc.Close()
+word.Quit()
+
+
+
+[{
+
+type:"单选",
+ques:[
+    {"name":"","answer":""},
+    {"name":"","answer":""},
+    {"name":"","answer":""},
+    {"name":"","answer":""},
+    {"name":"","answer":""},
+]
+}]

+ 112 - 0
parsedocx.py

@@ -0,0 +1,112 @@
+#-*-coding:utf-8 -*-
+import re,os
+import json,uuid
+from bs4 import BeautifulSoup
+from win32com.client import Dispatch
+
+class DocxConverter(object):
+    """
+    """
+    def __init__(self,docpath=None):
+        """
+        """
+        self.docpath = docpath
+        self.word = Dispatch("Word.Application")
+        self.word.Visible = 0
+        self.doc = word.Documents.Open(self.docpath)
+
+    def docx2html(self):
+        """
+        """
+        html = os.path.join(os.path.dirname(self.docpath),str(uuid.uuid4())+".html")
+        self.doc.SaveAs(html)
+        self.doc.Close()
+        self.word.Quit()
+        return html
+
+class QuestionsParser(object):
+    """试题解析
+    """
+    def __init__(self,name="test4.html"):
+        self.html = open(name,"r").read()
+        self.soup = BeautifulSoup(self.html,"html.parser")
+
+    def get_paragraphs(self):
+        """
+        """
+        wordsection = self.soup.find("div",class_="WordSection1")
+        #print wordsection
+        pars = wordsection.find_all("p")
+        return pars
+
+    def parse_questions(self):
+        """提取试题
+        """
+        que_type_dct = {}
+        paragraphs = self.get_paragraphs()
+        for i,p in enumerate(paragraphs):
+            print p.text
+            if u"【题型】" in p.text:
+                que_type_dct["type"] = p.text.split("、")[-1] 
+
+    def parse_questions(self):
+        """提取试题
+        """
+        data = []
+        tmp_val = {}
+        tx_name = ""
+        key = ""
+        paragraphs = self.get_paragraphs()
+        for i,p in enumerate(paragraphs):
+            if u"【题型】" in p.text:
+                tx_name = p.text 
+            if u"【题干】" in p.text:
+                key = "tg"
+                tmp_val["tx"] = tx_name
+                if tmp_val.get("tg"):
+                    data.append(tmp_val)
+                tmp_val = {"tg":"","tx":"","zsd":"","nd":"","da":"","jx":""}
+            if u"【知识点】" in p.text:
+                key = "zsd"
+            if u"【难度】" in p.text:
+                key = "nd"
+            if u"【答案】" in p.text:
+                key = "da"
+            if u"【解析】" in p.text:
+                key = "jx"
+
+            if key != "":
+                tmp_val[key] += p.__str__()
+
+        data.append(tmp_val)
+
+        return data
+
+    def get_questions(self):
+        """
+        """
+        questions = self.parse_questions()
+        for que in questions:
+            que["tx"] = que["tx"].split(u"、")[-1]
+            #que["tg"] = que["tg"].replace(u"【题干】","")
+            #que["zsd"] = que["zsd"].replace(u"【知识点】","")
+            #que["da"] = que["da"].replace(u"【答案】","")
+            #que["jx"] = que["jx"].replace(u"【解析】","")
+            que["qno"] = self.get_qno(que["tg"])
+        return questions
+
+    def get_qno(self,tg):
+        """提取题号
+        """
+        tgsoup = BeautifulSoup(tg,"html.parser")
+        tgtext = tgsoup.text
+        qno = re.search(r"\d+",tgtext.split(u"、")[0]).group()
+        return qno
+        
+
+questionparser =  QuestionsParser()
+
+if __name__ == "__main__":
+    ques = questionparser.get_questions()
+    with open("t.json","w+") as f:
+        f.write(json.dumps(ques))

TEMPAT SAMPAH
test.docx


TEMPAT SAMPAH
test4.docx


TEMPAT SAMPAH
test4.files/image001.gif


TEMPAT SAMPAH
test4.files/image001.png


TEMPAT SAMPAH
test4.files/image002.gif


TEMPAT SAMPAH
test4.files/image002.png


TEMPAT SAMPAH
test4.files/image003.gif


TEMPAT SAMPAH
test4.files/image003.png


TEMPAT SAMPAH
test4.files/image004.gif


TEMPAT SAMPAH
test4.files/image004.png


TEMPAT SAMPAH
test4.files/image005.gif


TEMPAT SAMPAH
test4.files/image005.png


TEMPAT SAMPAH
test4.files/image006.gif


TEMPAT SAMPAH
test4.files/image006.png


TEMPAT SAMPAH
test4.files/image007.gif


TEMPAT SAMPAH
test4.files/image007.png


TEMPAT SAMPAH
test4.files/image008.gif


TEMPAT SAMPAH
test4.files/image008.png


TEMPAT SAMPAH
test4.files/image009.gif


TEMPAT SAMPAH
test4.files/image009.png


TEMPAT SAMPAH
test4.files/image010.gif


TEMPAT SAMPAH
test4.files/image010.png


TEMPAT SAMPAH
test4.files/image011.gif


TEMPAT SAMPAH
test4.files/image011.png


TEMPAT SAMPAH
test4.files/image012.gif


TEMPAT SAMPAH
test4.files/image012.png


TEMPAT SAMPAH
test4.files/image013.gif


TEMPAT SAMPAH
test4.files/image013.png


TEMPAT SAMPAH
test4.files/image014.gif


TEMPAT SAMPAH
test4.files/image014.png


TEMPAT SAMPAH
test4.files/image015.gif


TEMPAT SAMPAH
test4.files/image015.png


TEMPAT SAMPAH
test4.files/image016.gif


TEMPAT SAMPAH
test4.files/image016.png


TEMPAT SAMPAH
test4.files/image017.gif


TEMPAT SAMPAH
test4.files/image017.png


TEMPAT SAMPAH
test4.files/image018.gif


TEMPAT SAMPAH
test4.files/image018.png


TEMPAT SAMPAH
test4.files/image019.gif


TEMPAT SAMPAH
test4.files/image019.png


TEMPAT SAMPAH
test4.files/image020.gif


TEMPAT SAMPAH
test4.files/image020.png


TEMPAT SAMPAH
test4.files/image021.gif


TEMPAT SAMPAH
test4.files/image021.png


TEMPAT SAMPAH
test4.files/image022.gif


TEMPAT SAMPAH
test4.files/image022.png


TEMPAT SAMPAH
test4.files/image023.gif


TEMPAT SAMPAH
test4.files/image023.png


TEMPAT SAMPAH
test4.files/image024.gif


TEMPAT SAMPAH
test4.files/image024.png


TEMPAT SAMPAH
test4.files/image025.gif


TEMPAT SAMPAH
test4.files/image025.png


TEMPAT SAMPAH
test4.files/image026.gif


TEMPAT SAMPAH
test4.files/image026.png


TEMPAT SAMPAH
test4.files/image027.gif


TEMPAT SAMPAH
test4.files/image027.png


TEMPAT SAMPAH
test4.files/image028.gif


TEMPAT SAMPAH
test4.files/image028.png


TEMPAT SAMPAH
test4.files/image029.gif


TEMPAT SAMPAH
test4.files/image029.png


TEMPAT SAMPAH
test4.files/image030.gif


TEMPAT SAMPAH
test4.files/image030.png


TEMPAT SAMPAH
test4.files/image031.gif


TEMPAT SAMPAH
test4.files/image031.png


TEMPAT SAMPAH
test4.files/image032.gif


TEMPAT SAMPAH
test4.files/image032.png


TEMPAT SAMPAH
test4.files/image033.gif


TEMPAT SAMPAH
test4.files/image033.png


TEMPAT SAMPAH
test4.files/image034.gif


TEMPAT SAMPAH
test4.files/image034.png


TEMPAT SAMPAH
test4.files/image035.gif


TEMPAT SAMPAH
test4.files/image035.png


TEMPAT SAMPAH
test4.files/image036.gif


TEMPAT SAMPAH
test4.files/image036.png


TEMPAT SAMPAH
test4.files/image037.gif


TEMPAT SAMPAH
test4.files/image037.png


TEMPAT SAMPAH
test4.files/image038.gif


TEMPAT SAMPAH
test4.files/image038.png


TEMPAT SAMPAH
test4.files/image039.gif


TEMPAT SAMPAH
test4.files/image039.png


TEMPAT SAMPAH
test4.files/image040.gif


TEMPAT SAMPAH
test4.files/image040.png


TEMPAT SAMPAH
test4.files/image041.gif


TEMPAT SAMPAH
test4.files/image041.png


TEMPAT SAMPAH
test4.files/image042.gif


TEMPAT SAMPAH
test4.files/image042.png


TEMPAT SAMPAH
test4.files/image043.gif


TEMPAT SAMPAH
test4.files/image043.png


TEMPAT SAMPAH
test4.files/image044.gif


TEMPAT SAMPAH
test4.files/image044.png


TEMPAT SAMPAH
test4.files/image045.gif


TEMPAT SAMPAH
test4.files/image045.png


TEMPAT SAMPAH
test4.files/image046.gif


TEMPAT SAMPAH
test4.files/image046.png


TEMPAT SAMPAH
test4.files/image047.gif


TEMPAT SAMPAH
test4.files/image047.png


TEMPAT SAMPAH
test4.files/image048.gif


+ 0 - 0
test4.files/image048.png


Beberapa file tidak ditampilkan karena terlalu banyak file yang berubah dalam diff ini