python爬蟲(chóng) 批量下載zabbix文檔代碼實(shí)例
這篇文章主要介紹了python爬蟲(chóng) 批量下載zabbix文檔代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(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("下載開(kāi)始") urls = get_urls() downloads(urls) print("下載完成") if __name__ == '__main__': main()
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- Python爬蟲(chóng)實(shí)戰(zhàn)案例之爬取喜馬拉雅音頻數(shù)據(jù)詳解
- python爬蟲(chóng)智能翻頁(yè)批量下載文件的實(shí)例詳解
- 用python批量下載apk
- python 根據(jù)列表批量下載網(wǎng)易云音樂(lè)的免費(fèi)音樂(lè)
- 用python爬蟲(chóng)批量下載pdf的實(shí)現(xiàn)
- python FTP批量下載/刪除/上傳實(shí)例
- 使用python3批量下載rbsp數(shù)據(jù)的示例代碼
- 如何基于Python批量下載音樂(lè)
- python實(shí)現(xiàn)抖音視頻批量下載
- python+POP3實(shí)現(xiàn)批量下載郵件附件
- python實(shí)現(xiàn)壁紙批量下載代碼實(shí)例
- Python實(shí)現(xiàn)Youku視頻批量下載功能
- Python爬蟲(chóng)之批量下載喜馬拉雅音頻
相關(guān)文章
pymongo給mongodb創(chuàng)建索引的簡(jiǎn)單實(shí)現(xiàn)方法
這篇文章主要介紹了pymongo給mongodb創(chuàng)建索引的簡(jiǎn)單實(shí)現(xiàn)方法,涉及Python使用pymongo模塊操作mongodb的技巧,需要的朋友可以參考下2015-05-05Python實(shí)現(xiàn)視頻自動(dòng)打碼的示例代碼
我們?cè)谟^(guān)看視頻的時(shí)候,有時(shí)候會(huì)出現(xiàn)一些奇怪的馬賽克,影響我們的觀(guān)影體驗(yàn),那么這些馬賽克是如何精確的加上去的呢?本文就來(lái)為大家詳細(xì)講講2022-04-04python實(shí)現(xiàn)對(duì)列表中的元素進(jìn)行倒序打印
今天小編就為大家分享一篇python實(shí)現(xiàn)對(duì)列表中的元素進(jìn)行倒序打印,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-11-11Python實(shí)現(xiàn)微信中找回好友、群聊用戶(hù)撤回的消息功能示例
這篇文章主要介紹了Python實(shí)現(xiàn)微信中找回好友、群聊用戶(hù)撤回的消息功能,結(jié)合實(shí)例形式分析了Python基于微信itchat模塊實(shí)現(xiàn)針對(duì)撤回消息的查看功能相關(guān)操作技巧,需要的朋友可以參考下2019-08-08解讀requests.session()獲取Cookies全過(guò)程
這篇文章主要介紹了解讀requests.session()獲取Cookies全過(guò)程,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2023-02-02基于Python實(shí)現(xiàn)捕獲,播放和保存攝像頭視頻
這篇文章主要為大家分享一下Python操作視頻最基本的操作,包括讀取和播放視頻和保存視頻。文中的示例代碼講解詳細(xì),感興趣的小伙伴可以了解一下2022-04-04音頻處理 windows10下python三方庫(kù)librosa安裝教程
這篇文章主要介紹了音頻處理 windows10下python三方庫(kù)librosa安裝方法,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2020-06-06