python爬蟲 批量下載zabbix文檔代碼實(shí)例
更新時(shí)間:2019年08月21日 10:23:07 作者:NAVYSUMMER
這篇文章主要介紹了python爬蟲 批量下載zabbix文檔代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
這篇文章主要介紹了python爬蟲 批量下載zabbix文檔代碼實(shí)例,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
# -*- 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("當(dāng)前下載url:")
print(download_url)
res = requests.get(url)
if res.status_code == 200 :
pattern = re.compile(r"<title>(.*?)</title>", 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('獲取文件名失敗,停止當(dāng)前下載')
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()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
您可能感興趣的文章:
- Python爬蟲實(shí)戰(zhàn)案例之爬取喜馬拉雅音頻數(shù)據(jù)詳解
- python爬蟲智能翻頁批量下載文件的實(shí)例詳解
- 用python批量下載apk
- python 根據(jù)列表批量下載網(wǎng)易云音樂的免費(fèi)音樂
- 用python爬蟲批量下載pdf的實(shí)現(xiàn)
- python FTP批量下載/刪除/上傳實(shí)例
- 使用python3批量下載rbsp數(shù)據(jù)的示例代碼
- 如何基于Python批量下載音樂
- python實(shí)現(xiàn)抖音視頻批量下載
- python+POP3實(shí)現(xiàn)批量下載郵件附件
- python實(shí)現(xiàn)壁紙批量下載代碼實(shí)例
- Python實(shí)現(xiàn)Youku視頻批量下載功能
- Python爬蟲之批量下載喜馬拉雅音頻
相關(guān)文章
Pygame實(shí)戰(zhàn)之檢測(cè)按鍵正確的小游戲
這篇文章主要為大家介紹了利用Pygame模塊實(shí)現(xiàn)的檢測(cè)按鍵正確的小游戲:每個(gè)字母有10秒的按鍵時(shí)間,如果按對(duì),則隨機(jī)產(chǎn)生新的字符,一共60s,如果時(shí)間到了,則游戲結(jié)束??靵砀S小編一起學(xué)習(xí)一下吧2021-12-12
python中pandas操作apply返回多列的實(shí)現(xiàn)
本文主要介紹了python中pandas操作apply返回多列的實(shí)現(xiàn),文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-08-08
Pipenv輕量級(jí)虛擬環(huán)境管理工具使用指南
這篇文章主要為大家介紹了Pipenv輕量級(jí)虛擬環(huán)境管理工具使用指南,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02
Python切片列表字符串如何實(shí)現(xiàn)切換
這篇文章主要介紹了Python切片列表字符串如何實(shí)現(xiàn)切換,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08

