NGP
Is life always this hard or is it just when you're a kid
当你老了,回顾一生,就会发觉:什么时候出国读书,什么时候决定做第一份职业、何时选定了对象而恋爱、什么时候结婚,其实都是命运的巨变。只是当时站在三岔路口,眼见风云千樯,你作出选择的那一日,在日记上,相当沉闷和平凡,当时还以为是生命中普通的一天。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
|
prefix='2019-' rootPicPath="D:\\DDDDDDDDDDDownload"
import requests
from bs4 import BeautifulSoup
import urllib.request
import time
COOKIES_ENABLED=False
def download(page_url,rootPicPath): header = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 UBrowser/6.1.2107.204 Safari/537.36'} html = requests.get(page_url,headers = header) soup = BeautifulSoup(html.text,'html.parser') all_img = soup.find_all('img') time.sleep(1) n=1 for img in all_img: picUrl = img.get('src') picName= str(prefix) + "-" + str(n) + ".jpg" n+=1 picPath = rootPicPath + "\\" + picName
try: urllib.request.urlretrieve(picUrl,picPath) print(picName+"————下载完成") except Exception as err: print(picName+"————————下载失败") print() print('error: ',err) print()
time.sleep(1)
def mkdir(path): import os path = path.strip() path = path.rstrip("\\") isExists = os.path.exists(path) if not isExists: os.makedirs(path) return True else: return False
if __name__=='__main__': url_list = [ "https://blog.csdn.net/qq_35208390/article/details/86496498", ] mkdir(rootPicPath) for link in url_list: download(link,rootPicPath)
|
This article just represents my own viewpoint. If there is something wrong, please correct me.