text: import os
  import base64
  import re
  from bs4 import BeautifulSoup
  from selenium import webdriver
  from selenium.webdriver.chrome.options import Options
  
  base_url = "https://developer.work.weixin.qq.com/document/path"
  
  path = "E:\mhtml\workWeixin\\api_doc\developer.work.weixin.qq.com\document\path"
  
  base_pic_url_list = ['http://p.qpic.cn/pic_wework', 'https://wwcdn.weixin.qq.com', 'https://wework.qpic.cn', 'https://res.mail.qq.com', 'https://rescdn.qqmail.com', 'http://p.qlogo.cn', 'https://res.wx.qq.com']
  
  
  http_headers = { 'Accept': '*/*','Connection': 'keep-alive', 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/53.0.2785.116 Safari/537.36'}
  
  files = os.listdir(path)
  
  chrome_options = Options()
  chrome_options.add_argument('--headless')
  browser = webdriver.Chrome(options=chrome_options)
  browser.set_page_load_timeout(3)
  
  for mhtmlFile in files:
      if not os.path.isdir(mhtmlFile):
          with open(path + '\\' + mhtmlFile, 'r', encoding="utf-8") as f:
              content = f.read()
              
              img_list = re.compile(r'<img.*?src="(http.*?)".*?>', re.S).findall(content)
              for img in img_list:
                  os.system(f"""wget.exe -P ./api_doc -r -p -np -k "{img}""")
              
              content = content.replace(base_url + "/", "")
              for item in base_pic_url_list:
                  if (item.startswith('http://')):
                      content = content.replace(item, item.replace('http://', '../../../'))
                  elif (item.startswith('https://')):
                      content = content.replace(item, item.replace('https://', '../../../'))
              with open(path + '\\' + mhtmlFile, 'w+', encoding="utf-8") as f:
                      f.write(content)
                      
              soup = BeautifulSoup(content, 'html.parser')
              # 获取页面内所有http链接
              for link in soup.findAll('a', attrs={"rel": "nofollow"}):
                  href = link['href']
                  res_link = base_url + '/' + href
                  print("origin " + res_link)
                  try:
                      browser.get(res_link)
                  except Exception as e:
                      print("selenium get redirect url error, current url: " + res_link)
                  redirect_url = browser.current_url
                  if 'path/' in redirect_url:
                      content = content.replace(href, redirect_url.split('path/')[1])
                      with open(path + '\\' + mhtmlFile, 'w+', encoding="utf-8") as f:
                          f.write(content)
  browser.close()
  browser.quit()
                  
          