日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 综合教程 >内容正文

综合教程

图集谷-写真集-爬虫-2.1「建议收藏」

發(fā)布時間:2023/12/19 综合教程 35 生活家
生活随笔 收集整理的這篇文章主要介紹了 图集谷-写真集-爬虫-2.1「建议收藏」 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

為了使爬蟲代碼更加扁平化,因此,我對2.0版本爬蟲進行了一定的修改。

話不多說,請看代碼。

# 導(dǎo)入庫
import os, time, requests
 
# 請求頭
headers = {
  'User-Agent': 'Chrome 10.0'
}
 
# 圖片數(shù)據(jù)列表
pictures = []
 
# 獲取圖片數(shù)據(jù)
def get_pic(url, nums):
    for num in range(0, int(nums)):
        url_all = str(url) + f'{str(num)}.jpg'
        res = requests.get(url=url_all, headers=headers)
        pic_content = res.content
        pictures.append(pic_content)
        time.sleep(0.5)
 
# 創(chuàng)建目的文件夾
def get_path(path_name):
    if not os.path.exists(f'C:/Users/liu/Desktop/圖集/{path_name}'):
        os.mkdir(f'C:/Users/liu/Desktop/圖集/{path_name}')
    else:
        pass
 
# 保存圖片數(shù)據(jù)
def save_data():
    for pic,i in zip(pictures, range(int(Num))):
        picture = open(f'C:/Users/liu/Desktop/圖集/{str(Page_Num)}/{str(i)}.jpg', 'wb')
        picture.write(pic)
        picture.close()
# 主函數(shù),調(diào)用函數(shù)
def main():
    url = f'https://tjg.gzhuibei.com/a/1/{str(Page_Num)}/'    # 傳入網(wǎng)頁數(shù)據(jù)
    get_path(path_name=Page_Num)
    get_pic(url=url, nums=Num)
    save_data()
 
# 主程序入口
if __name__ == '__main__':
    Page_Num = input('Enter the Page_name:')    # Page_Num指下文url所代指的數(shù)字
    Num = int(input('Enter the Num:')) + 1    # Num為寫真集的圖片數(shù)
    print('Finish!')

大家有任何疑問,都可以在下面評論區(qū)進行留言,我會不定時的對評論進行回復(fù)。

感謝大家的支持!

總結(jié)

以上是生活随笔為你收集整理的图集谷-写真集-爬虫-2.1「建议收藏」的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。