日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

python爬蟲 批量下載zabbix文檔代碼實例

系統 1771 0

這篇文章主要介紹了python爬蟲 批量下載zabbix文檔代碼實例,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下

            
# -*- coding: UTF-8 -*-
import requests,re,time
url = 'https://www.zabbix.com/documentation/3.4/zh/manual'
base_url = 'https://www.zabbix.com/documentation/3.4/'
seconds = 1
err_url = []
def get_urls():
  res = requests.get(url)
  content = res.text
  pattern = re.compile(r"indexmenu_4848130395ca30b274d8bd.add[(]'(zh/manual.*?)[']", re.S)
  routes = pattern.findall(content)
  urls = [base_url+item for item in routes]
  return urls 
def download(url):
  download_url = url + "?do=export_pdf"
  print("當前下載url:")
  print(download_url)
  res = requests.get(url)
  if res.status_code == 200 :
    pattern = re.compile(r"
            ", re.S)
    title = pattern.findall(res.text)[0].encode("utf-8")
    try:
      filename = title.replace('\\','-').replace('/','-').replace('"','-').replace('*','-').replace('?','-').replace(':','-').replace('<','-').replace('>','-').replace('|','-')
    except Exception:
       title = pattern.findall(res.text)[0]
    filename = title.replace('\\','-').replace('/','-').replace('"','-').replace('*','-').replace('?','-').replace(':','-').replace('<','-').replace('>','-').replace('|','-')
    file = filename + '.pdf'
    res = requests.get(download_url)
    if res.status_code == 200 :
      with open(file,"wb") as f:
        f.write(res.content)
      print('下載成功')
    else:
      print('下載失敗')
      err_url.append(download_url)
  else:
    print('獲取文件名失敗,停止當前下載')
    err_url.append(download_url) 
def downloads(urls):
  for url in urls:
    download(url)
    time.sleep( seconds )
  if len(err_url) :
    print("下載失敗的URL:")
    print(err_url) 
def main():
  print("下載開始")
  urls = get_urls()
  downloads(urls)
  print("下載完成") 
if __name__ == '__main__':
  main()
          

以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。


更多文章、技術交流、商務合作、聯系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 石阡县| 将乐县| 苗栗市| 秀山| 扎兰屯市| 大连市| 洪湖市| 玉溪市| 剑阁县| 高密市| 山阴县| 黄大仙区| 天全县| 沈丘县| 睢宁县| 年辖:市辖区| 宁远县| 扎赉特旗| 南岸区| 抚宁县| 嘉禾县| 崇文区| 蓝山县| 台山市| 嘉峪关市| 吉木萨尔县| 福州市| 盐源县| 西宁市| 高清| 普定县| 若羌县| 平罗县| 昭觉县| 托克逊县| 陕西省| 天等县| 中江县| 克山县| 黑山县| 乌鲁木齐县|