from win32com.client import Dispatch
import time
myWord = Dispatch('Word.Application')
myWord.Visible = 1 # comment out for production
url = 'http://127.0.0.1:8000/t/%E6%96%B0%E9%97%BB/1.html'
# use word Open web pages to maximize formatting
myWord.Documents.Open(url) # open file
doc = myWord.ActiveDocument
rngPage = doc.Bookmarks("\Page").Range
page_count = doc.ActiveWindow.Panes(1).Pages.Count
print('pagecount', page_count)
# time.sleep(1000)
# Future generations
myWord.Selection.WholeStory()
# Copy
myWord.Selection.Copy()
doc_add = myWord.Documents.Open(r"C:\Users\Administrator\Documents\1.docx")
wdRange = doc_add.Content
print(doc.Name)
# Activate doc_add
myWord.Documents(doc_add).Activate()
doc = myWord.ActiveDocument
print(doc.Name)
# Copy paste twice
myWord.Selection.Paste()
myWord.Selection.Paste()
myWord.ActiveDocument.SaveAs('172.docx',16)
myWord.Quit() # close Word.Application
Reference resources
Official documents
https://docs.microsoft.com/en-us/office/vba/api/word.words
https://stackoverflow.com/questions/15274601/opening-a-ms-word-file-in-pywin32
https://www.cnblogs.com/zhuminghui/p/11765401.html