```py
import requests
from bs4 import BeautifulSoup
import json,sys,time,re,os
class download_mzt():
def __init__(self):
self.url_name='https://www.mzitu.com/'
self.header={
'Referer': 'https://www.mzitu.com',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36'
}
self.title_list=[]
# 獲取首頁所有連接的函數
def get_list(self):
rq=requests.get(url=self.url_name,headers=self.header)
sp=BeautifulSoup(rq.text,'html.parser')
text=sp.find_all('div',class_='postlist')[0].find_all('a',target='_blank')
for i in text:
title=i.get_text()
url=i.get('href')
if title :
self.title_list.append({
'title':title,
'url':url
})
# for n in self.title_list:
# print(n)
# 定義獲取最大列表的函數
def get_maxpage(self):
for name in self.title_list:
urls=name['url']
rq = requests.get(url=urls, headers=self.header)
sp = BeautifulSoup(rq.text, 'html.parser')
text = sp.find_all('div', class_='pagenavi')[0].find_all('span')
maxpag = text[-2].get_text()
# print(maxpag)
name['maxpag']=int(maxpag)
# 獲取套圖的所有地址
def get_ever_url(self,dic):
print('下載:%s,\t 頁數%s'%(dic['title'],dic['maxpag']))
for i in range(1,dic['maxpag']):
# print(i)
page_url="%s/%s"%(dic['url'],i)
rq=requests.get(url=page_url,headers=self.header)
sp=BeautifulSoup(rq.text,'html.parser')
text=sp.find_all('div',class_='main-image')[0].find_all('img')[0]
pic_url=text.get('src')
name=re.split('/',pic_url)[5]
self.down_pic(pic_url,dic['title'],name)
# print('\t\t下載第%s頁,名字%s'%(i,name))
# time.sleep(0.5)
# print(pic_url,name)
sys.stdout.write("\r")
sys.stdout.write("%s%% | %s" %(int(i/dic['maxpag']*100),i*'|'))
sys.stdout.flush()
# 定義下載函數
def down_pic(self,pic_url,title,name):
if not os.path.exists(title):
os.mkdir(title)
rq=requests.get(url=pic_url,headers=self.header)
with open("%s/%s"%(title,name),'wb') as f:
f.write(rq.content)
f.close()
if __name__=="__main__":
dm=download_mzt()
# dm.get_list()
# dm.get_maxpage()
# for dic in dm.title_list:
# print(dic)
# dm.get_ever_url(dic)
dic={'title': '秒殺日本AV!夏詩詩老師真實教室場景上演香艷課堂', 'url': 'https://www.mzitu.com/224623', 'maxpag': 78}
dm.get_ever_url(dic)
```
- 基礎部分
- 基礎知識
- 變量
- 數據類型
- 數字與布爾詳解
- 列表詳解list
- 字符串詳解str
- 元組詳解tup
- 字典詳解dict
- 集合詳解set
- 運算符
- 流程控制與循環
- 字符編碼
- 編的小程序
- 三級菜單
- 斐波那契數列
- 漢諾塔
- 文件操作
- 函數相關
- 函數基礎知識
- 函數進階知識
- lambda與map-filter-reduce
- 裝飾器知識
- 生成器和迭代器
- 琢磨的小技巧
- 通過operator函數將字符串轉換回運算符
- 目錄規范
- 異常處理
- 常用模塊
- 模塊和包相關概念
- 絕對導入&相對導入
- pip使用第三方源
- time&datetime模塊
- random隨機數模塊
- os 系統交互模塊
- sys系統模塊
- shutil復制&打包模塊
- json&pickle&shelve模塊
- xml序列化模塊
- configparser配置模塊
- hashlib哈希模塊
- subprocess命令模塊
- 日志logging模塊基礎
- 日志logging模塊進階
- 日志重復輸出問題
- re正則表達式模塊
- struct字節處理模塊
- abc抽象類與多態模塊
- requests與urllib網絡訪問模塊
- 參數控制模塊1-optparse-過時
- 參數控制模塊2-argparse
- pymysql數據庫模塊
- requests網絡請求模塊
- 面向對象
- 面向對象相關概念
- 類與對象基礎操作
- 繼承-派生和組合
- 抽象類與接口
- 多態與鴨子類型
- 封裝-隱藏與擴展性
- 綁定方法與非綁定方法
- 反射-字符串映射屬性
- 類相關內置方法
- 元類自定義及單例模式
- 面向對象的軟件開發
- 網絡-并發編程
- 網絡編程SOCKET
- socket簡介和入門
- socket代碼實例
- 粘包及粘包解決辦法
- 基于UDP協議的socket
- 文件傳輸程序實戰
- socketserver并發模塊
- 多進程multiprocessing模塊
- 進程理論知識
- 多進程與守護進程
- 鎖-信號量-事件
- 隊列與生產消費模型
- 進程池Pool
- 多線程threading模塊
- 進程理論和GIL鎖
- 死鎖與遞歸鎖
- 多線程與守護線程
- 定時器-條件-隊列
- 線程池與進程池(新方法)
- 協程與IO模型
- 協程理論知識
- gevent與greenlet模塊
- 5種網絡IO模型
- 非阻塞與多路復用IO實現
- 帶著目標學python
- Pycharm基本使用
- 爬蟲
- 案例-爬mzitu美女
- 案例-爬小說
- beautifulsoup解析模塊
- etree中的xpath解析模塊
- 反爬對抗-普通驗證碼
- 反爬對抗-session登錄
- 反爬對抗-代理池
- 爬蟲技巧-線程池
- 爬蟲對抗-圖片懶加載
- selenium瀏覽器模擬