爬天极网美女预览图版一:

import os
import requests
from bs4 import BeautifulSoup
base_path = os.path.dirname(os.path.abspath(__file__))
img1_path = os.path.join(base_path,"img1")
response = requests.get("http://pic.yesky.com/koreastar/album/381/421714881.shtml")
soup = BeautifulSoup(response.text,"html.parser")
div_obj = soup.find(name = "div",attrs={"class":"viewport"})
list_dl = div_obj.find_all(name = "li")
for li in list_dl:
img = li.find(name = "img")
img_src = img.get("src")
img_response = requests.get(img_src)
file_path = os.path.join(img1_path,img_src.rsplit("/",1)[-1])
with open(file_path,"wb") as f:
f.write(img_response.content)
效果图:

posted @ 2020-01-17 21:46  干it的小张  阅读(234)  评论(0编辑  收藏  举报